1
0
mirror of synced 2025-01-26 10:11:41 +03:00

103 lines
2.3 KiB
PHP
Raw Normal View History

2019-12-26 17:47:33 +03:00
<?php
namespace RetailCrm\DeliveryModuleBundle\Model;
use JMS\Serializer\Annotation as Serializer;
2020-08-18 17:39:55 +03:00
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
2019-12-26 17:47:33 +03:00
class Package
{
/**
* Идентификатор упаковки
2020-08-18 17:39:55 +03:00
*
2019-12-26 17:47:33 +03:00
* @var string
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("packageId")
* @Serializer\Type("string")
*/
public $packageId;
/**
* Вес г.
2020-08-18 17:39:55 +03:00
*
2019-12-26 17:47:33 +03:00
* @var float
*
* @Serializer\Groups({"request", "calculate"})
* @Serializer\SerializedName("weight")
* @Serializer\Type("float")
*/
public $weight;
/**
* Ширина мм.
2020-08-18 17:39:55 +03:00
*
* @var int
2019-12-26 17:47:33 +03:00
*
* @Serializer\Groups({"request", "calculate"})
* @Serializer\SerializedName("width")
* @Serializer\Type("integer")
*/
public $width;
/**
* Длина мм.
2020-08-18 17:39:55 +03:00
*
* @var int
2019-12-26 17:47:33 +03:00
*
* @Serializer\Groups({"request", "calculate"})
* @Serializer\SerializedName("length")
* @Serializer\Type("integer")
*/
public $length;
/**
* Высота мм.
2020-08-18 17:39:55 +03:00
*
* @var int
2019-12-26 17:47:33 +03:00
*
* @Serializer\Groups({"request", "calculate"})
* @Serializer\SerializedName("height")
* @Serializer\Type("integer")
*/
public $height;
/**
* Содержимое упаковки
2020-08-18 17:39:55 +03:00
*
2019-12-26 17:47:33 +03:00
* @var PackageItem[]
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("items")
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\PackageItem>")
*/
public $items;
public function __construct($weight = null, $width = null, $length = null, $height = null)
{
$this->weight = $weight;
$this->width = $width;
$this->length = $length;
$this->height = $height;
}
public function getVolume()
{
2020-08-18 17:39:55 +03:00
if (null !== $this->length
&& null !== $this->width
&& null !== $this->height
2019-12-26 17:47:33 +03:00
) {
return $this->length * $this->width * $this->height;
} else {
return false;
}
}
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata
->addPropertyConstraint('weight', new Assert\NotBlank());
}
}