%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 3.144.224.76 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/sale/lib/ |
Upload File : |
<?php namespace Bitrix\Sale; use Bitrix\Main\Error; use Bitrix\Main\Localization\Loc; use Bitrix\Sale; Loc::loadMessages(__FILE__); /** * Class OrderFacade * @package Bitrix\Sale */ class OrderFacade { /** * @param $id * @return Result * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentNullException * @throws \Bitrix\Main\ArgumentOutOfRangeException * @throws \Bitrix\Main\NotImplementedException * @throws \Bitrix\Main\ObjectNotFoundException * @throws \Bitrix\Main\SystemException */ public static function payOrder($id) { $result = new Result(); $registry = Registry::getInstance(Registry::REGISTRY_TYPE_ORDER); /** @var Order $orderClassName */ $orderClassName = $registry->getOrderClassName(); $order = $orderClassName::load($id); if (!$order) { $result->addError(new Error(Loc::getMessage('SALE_GROUP_ACTION_ERR_ORDER_NOT_FOUND'))); return $result; } $collection = $order->getPaymentCollection(); /** @var Payment $payment */ foreach ($collection as $payment) { if (!$payment->isPaid()) { $r = $payment->setPaid('Y'); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } } } if (!$order->isPaid()) { $payment = static::createFinalPayment($order); if ($payment === null) { $result->addError( new Error( Loc::getMessage('SALE_GROUP_ACTION_ERR_PAYMENT_CREATE') ) ); return $result; } } $r = $order->save(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } return $result; } /** * @param $id * @return Result * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentNullException * @throws \Bitrix\Main\ArgumentOutOfRangeException * @throws \Bitrix\Main\ObjectNotFoundException */ public static function cancelPayOrder($id) { $result = new Result(); $registry = Registry::getInstance(Registry::REGISTRY_TYPE_ORDER); /** @var Order $orderClassName */ $orderClassName = $registry->getOrderClassName(); $order = $orderClassName::load($id); if (!$order) { $result->addError(new Error(Loc::getMessage('SALE_GROUP_ACTION_ERR_ORDER_NOT_FOUND'))); return $result; } $collection = $order->getPaymentCollection(); /** @var Payment $payment */ foreach ($collection as $payment) { if ($payment->isPaid()) { $r = $payment->setPaid('N'); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } } } $r = $order->save(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } return $result; } /** * @param $id * @return Result * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentNullException * @throws \Bitrix\Main\ArgumentOutOfRangeException * @throws \Bitrix\Main\ArgumentTypeException * @throws \Bitrix\Main\NotSupportedException * @throws \Bitrix\Main\ObjectNotFoundException * @throws \Bitrix\Main\SystemException */ public static function deductOrder($id) { $result = new Result(); $registry = Registry::getInstance(Registry::REGISTRY_TYPE_ORDER); /** @var Order $orderClassName */ $orderClassName = $registry->getOrderClassName(); $order = $orderClassName::load($id); if (!$order) { $result->addError(new Error(Loc::getMessage('SALE_GROUP_ACTION_ERR_ORDER_NOT_FOUND'))); return $result; } $collection = $order->getShipmentCollection()->getNotSystemItems(); /** @var Shipment $shipment */ foreach ($collection as $shipment) { if (!$shipment->isShipped()) { $r = $shipment->setField('DEDUCTED', 'Y'); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } } } if (!$order->isShipped()) { $shipment = static::createFinalShipment($order); if ($shipment === null) { $result->addError( new Error( Loc::getMessage('SALE_GROUP_ACTION_ERR_SHIPMENT_CREATE') ) ); return $result; } } $r = $order->save(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } return $result; } /** * @param $id * @return Result * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentNullException * @throws \Bitrix\Main\ArgumentOutOfRangeException * @throws \Bitrix\Main\NotSupportedException * @throws \Bitrix\Main\SystemException */ public static function cancelDeductOrder($id) { $result = new Result(); $registry = Registry::getInstance(Registry::REGISTRY_TYPE_ORDER); /** @var Order $orderClassName */ $orderClassName = $registry->getOrderClassName(); $order = $orderClassName::load($id); if (!$order) { $result->addError(new Error(Loc::getMessage('SALE_GROUP_ACTION_ERR_ORDER_NOT_FOUND'))); return $result; } $collection = $order->getShipmentCollection()->getNotSystemItems(); /** @var Shipment $shipment */ foreach ($collection as $shipment) { if ($shipment->isShipped()) { $r = $shipment->setField('DEDUCTED', 'N'); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } } } $r = $order->save(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } return $result; } /** * @param Order $order * @return Payment|null * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentOutOfRangeException * @throws \Bitrix\Main\NotImplementedException * @throws \Bitrix\Main\ObjectNotFoundException * @throws \Bitrix\Main\SystemException */ protected static function createFinalPayment(Order $order) { $price = $order->getPrice(); $paidSum = $order->getPaymentCollection()->getPaidSum(); $payment = $order->getPaymentCollection()->createItem(); $payment->setField('SUM', $price - $paidSum); $paySystemId = static::getPaySystemId($payment); if ($paySystemId === 0) { return null; } $service = Sale\PaySystem\Manager::getObjectById($paySystemId); $payment->setPaySystemService($service); $payment->setPaid('Y'); return $payment; } /** * @param Order $order * @return Shipment * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentNullException * @throws \Bitrix\Main\ArgumentOutOfRangeException * @throws \Bitrix\Main\ArgumentTypeException * @throws \Bitrix\Main\NotSupportedException * @throws \Bitrix\Main\ObjectNotFoundException * @throws \Bitrix\Main\SystemException */ protected static function createFinalShipment(Order $order) { $collection = $order->getShipmentCollection(); $deliveryId = static::getDeliveryId(); if ((int)$deliveryId == 0) { return null; } $delivery = Sale\Delivery\Services\Manager::getObjectById($deliveryId); $shipment = $collection->createItem($delivery); $itemCollection = $shipment->getShipmentItemCollection(); $system = $collection->getSystemShipment(); $systemItemCollection = $system->getShipmentItemCollection(); /** @var Sale\ShipmentItem $shipmentItem */ foreach ($systemItemCollection as $shipmentItem) { $item = $itemCollection->createItem($shipmentItem->getBasketItem()); $item->setQuantity($shipmentItem->getQuantity()); } $shipment->setField('DEDUCTED', 'Y'); return $shipment; } /** * @param Payment $payment * @return array|int * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\SystemException */ protected static function getPaySystemId(Payment $payment) { $paySystemList = Sale\PaySystem\Manager::getListWithRestrictions($payment); foreach ($paySystemList as $paySystem) { if ((int)$paySystem['ID'] === (int)Sale\PaySystem\Manager::getInnerPaySystemId()) { continue; } return $paySystem['ID']; } return 0; } /** * @return int * @throws \Bitrix\Main\SystemException */ protected static function getDeliveryId() { return Sale\Delivery\Services\Manager::getEmptyDeliveryServiceId(); } }