diff --git a/README.md b/README.md index 245761f..ea9bc60 100644 --- a/README.md +++ b/README.md @@ -140,10 +140,10 @@ try { $order->setPaymentAmount(1300); // Сумма к оплате $order->setDeliveryAmount(300); // Стоимость доставки $order->setComment('Тестовый заказ'); // Комментарий к заказу - // $order->setVid(1); // Тип доставки (1 - ПВЗ, 2 - КД) + // $order->setVid(\WildTuna\BoxberrySdk\Entity\Order::PVZ); // Тип доставки (1 - ПВЗ, 2 - КД, 3 - Почта России) // $order->setPvzCode(61831); // Код ПВЗ // $order->setPointOfEntry('010'); // Код пункта поступления - $order->setVid(2); // Тип доставки (1 - ПВЗ, 2 - КД) + $order->setVid(\WildTuna\BoxberrySdk\Entity\Order::COURIER); // Тип доставки (1 - ПВЗ, 2 - КД, 3 - Почта России) $customer = new \WildTuna\BoxberrySdk\Entity\Customer(); $customer->setFio('Иванов Петр Николаевич'); // ФИО получателя @@ -187,6 +187,23 @@ try { $item->setVat(20); // Ставка НДС $item->setUnit('шт'); // Единица измерения $order->setItems($item); + $order->setSenderName('ООО Ромашка'); // Наименование отправителя + $order->setIssue(\WildTuna\BoxberrySdk\Entity\Order::TOI_DELIVERY_WITH_OPENING_AND_VERIFICATION); // вид выдачи (см. константы класса) + + // Для отправления Почтой России необходимо заполнить дополнительные параметры + $russianPostParams = new \WildTuna\BoxberrySdk\Entity\RussianPostParams(); + $russianPostParams->setType(\WildTuna\BoxberrySdk\Entity\RussianPostParams::PT_POSILKA); // Тип отправления (см. константы класса) + $russianPostParams->setFragile(true); // Хрупкая посылка + $russianPostParams->setStrong(true); // Строгий тип + $russianPostParams->setOptimize(true); // Оптимизация тарифа + $russianPostParams->setPackingType(\WildTuna\BoxberrySdk\Entity\RussianPostParams::PACKAGE_IM_MORE_160); // Тип упаковки (см. константы класса) + $russianPostParams->setPackingStrict(false); // Строгая упаковка + + // Габариты тарного места (см) Обязательны для доставки Почтой России. + $russianPostParams->setLength(10); + $russianPostParams->setWidth(10); + $russianPostParams->setHeight(10); + $result = $bbClient->createOrder($order); /* diff --git a/src/Entity/Order.php b/src/Entity/Order.php index ff468e3..bace1e0 100644 --- a/src/Entity/Order.php +++ b/src/Entity/Order.php @@ -3,6 +3,16 @@ class Order { + // Типы выдачи заказа получателю (TOI_*) + const TOI_DELIVERY_WITHOUT_OPENING = 0; // выдача без вскрытия + const TOI_DELIVERY_WITH_OPENING_AND_VERIFICATION = 1; // выдача со вскрытием и проверкой комплектности + const TOI_PARTIAL_ISSUE = 2; // выдача части вложения + + // Виды доставки (vid) + const PVZ = 1; // Доставка до пункта выдачи (ПВЗ) + const COURIER = 2; // Курьерская доставка (КД) + const RUSSIAN_POST = 3; // Доставка Почтой России (ПР) + /** * Трекинг-код ранее созданной посылки * @var string @@ -97,6 +107,24 @@ class Order */ private $comment = ''; + /** + * Вид выдачи + * @var int + */ + private $issue = null; + + /** + * Наименование магазина отправителя для sms/e-mail оповещений и внутренней маркировки Boxberry + * @var string + */ + private $sender_name = null; + + /** + * Параметры для отправления Почтой России (vid = 3) + * @var RussianPostParams + */ + private $russian_post_params = null; + public function asArr() { $params = []; @@ -137,14 +165,25 @@ public function asArr() $kurdost['timep'] = $this->customer->getDeliveryTime(); $kurdost['delivery_date'] = $this->delivery_date; $kurdost['comentk'] = $this->comment; + + // Доп. параметры для Почты России + if (!empty($this->russian_post_params)) { + $kurdost['type'] = $this->russian_post_params->getType(); + $kurdost['fragile'] = (string)($this->russian_post_params->isFragile()) ? '1' : '0'; + $kurdost['strong'] = (string)($this->russian_post_params->isStrong()) ? '1' : '0'; + $kurdost['optimize'] = (string)($this->russian_post_params->isOptimize()) ? '1' : '0'; + $kurdost['packing_type'] = $this->russian_post_params->getPackingType(); + $kurdost['packing_strict'] = $this->russian_post_params->isPackingStrict(); + } + $params['kurdost'] = $kurdost; if (empty($this->places)) throw new \InvalidArgumentException('В заказе не заполнена информация о местах!'); - if (count($this->places) > 5) - throw new \InvalidArgumentException('В заказе не может быть больше 5 мест!'); + /*if (count($this->places) > 5) + throw new \InvalidArgumentException('В заказе не может быть больше 5 мест!');*/ $weights = []; /** @@ -162,6 +201,13 @@ public function asArr() } $params['weights'] = $weights; + // Габариты места для Почты России + if (!empty($this->russian_post_params)) { + $params['weights']['x'] = $this->russian_post_params->getWidth(); + $params['weights']['y'] = $this->russian_post_params->getHeight(); + $params['weights']['z'] = $this->russian_post_params->getLength(); + } + if (empty($this->items)) throw new \InvalidArgumentException('В заказе не заполнены товары!'); @@ -180,6 +226,8 @@ public function asArr() } $params['items'] = $items; + $params['issue'] = $this->issue; + $params['sender_name'] = $this->sender_name; return $params; } @@ -423,4 +471,36 @@ public function setComment($comment) { $this->comment = $comment; } + + /** + * @return int + */ + public function getIssue() + { + return $this->issue; + } + + /** + * @param int $issue + */ + public function setIssue($issue) + { + $this->issue = $issue; + } + + /** + * @return string + */ + public function getSenderName() + { + return $this->sender_name; + } + + /** + * @param string $sender_name + */ + public function setSenderName($sender_name) + { + $this->sender_name = $sender_name; + } } \ No newline at end of file diff --git a/src/Entity/RussianPostParams.php b/src/Entity/RussianPostParams.php new file mode 100644 index 0000000..e76bba9 --- /dev/null +++ b/src/Entity/RussianPostParams.php @@ -0,0 +1,216 @@ +type; + } + + /** + * @param int $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return bool + */ + public function isFragile() + { + return $this->fragile; + } + + /** + * @param bool $fragile + */ + public function setFragile($fragile) + { + $this->fragile = $fragile; + } + + /** + * @return bool + */ + public function isStrong() + { + return $this->strong; + } + + /** + * @param bool $strong + */ + public function setStrong($strong) + { + $this->strong = $strong; + } + + /** + * @return bool + */ + public function isOptimize() + { + return $this->optimize; + } + + /** + * @param bool $optimize + */ + public function setOptimize($optimize) + { + $this->optimize = $optimize; + } + + /** + * @return int + */ + public function getPackingType() + { + return $this->packing_type; + } + + /** + * @param int $packing_type + */ + public function setPackingType($packing_type) + { + $this->packing_type = $packing_type; + } + + /** + * @return bool + */ + public function isPackingStrict() + { + return $this->packing_strict; + } + + /** + * @param bool $packing_strict + */ + public function setPackingStrict($packing_strict) + { + $this->packing_strict = $packing_strict; + } + + /** + * @return null + */ + public function getLength() + { + return $this->length; + } + + /** + * @param null $length + */ + public function setLength($length) + { + $this->length = $length; + } + + /** + * @return null + */ + public function getWidth() + { + return $this->width; + } + + /** + * @param null $width + */ + public function setWidth($width) + { + $this->width = $width; + } + + /** + * @return null + */ + public function getHeight() + { + return $this->height; + } + + /** + * @param null $height + */ + public function setHeight($height) + { + $this->height = $height; + } +} \ No newline at end of file