27 public static function payOrder($id)
33 $orderClassName = $registry->getOrderClassName();
35 $order = $orderClassName::load($id);
42 $collection = $order->getPaymentCollection();
44 foreach ($collection as $payment)
46 if (!$payment->isPaid())
48 $r = $payment->setPaid(
'Y');
51 $result->addErrors($r->getErrors());
57 if (!$order->isPaid())
59 $payment = static::createFinalPayment($order);
60 if ($payment ===
null)
74 $result->addErrors($r->getErrors());
88 public static function cancelPayOrder($id)
94 $orderClassName = $registry->getOrderClassName();
96 $order = $orderClassName::load($id);
103 $collection = $order->getPaymentCollection();
105 foreach ($collection as $payment)
107 if ($payment->isPaid())
109 $r = $payment->setPaid(
'N');
110 if (!$r->isSuccess())
112 $result->addErrors($r->getErrors());
119 if (!$r->isSuccess())
121 $result->addErrors($r->getErrors());
138 public static function deductOrder($id)
144 $orderClassName = $registry->getOrderClassName();
146 $order = $orderClassName::load($id);
153 $collection = $order->getShipmentCollection()->getNotSystemItems();
156 foreach ($collection as $shipment)
158 if (!$shipment->isShipped())
160 $r = $shipment->setField(
'DEDUCTED',
'Y');
161 if (!$r->isSuccess())
163 $result->addErrors($r->getErrors());
169 if (!$order->isShipped())
171 $shipment = static::createFinalShipment($order);
172 if ($shipment ===
null)
184 if (!$r->isSuccess())
186 $result->addErrors($r->getErrors());
201 public static function cancelDeductOrder($id)
207 $orderClassName = $registry->getOrderClassName();
209 $order = $orderClassName::load($id);
216 $collection = $order->getShipmentCollection()->getNotSystemItems();
219 foreach ($collection as $shipment)
221 if ($shipment->isShipped())
223 $r = $shipment->setField(
'DEDUCTED',
'N');
224 if (!$r->isSuccess())
226 $result->addErrors($r->getErrors());
233 if (!$r->isSuccess())
235 $result->addErrors($r->getErrors());
252 $price = $order->getPrice();
253 $paidSum = $order->getPaymentCollection()->getPaidSum();
255 $payment = $order->getPaymentCollection()->createItem();
256 $payment->setField(
'SUM', $price - $paidSum);
258 $paySystemId = static::getPaySystemId($payment);
259 if ($paySystemId === 0)
264 $service = Sale\PaySystem\Manager::getObjectById($paySystemId);
265 $payment->setPaySystemService($service);
267 $payment->setPaid(
'Y');
283 protected static function createFinalShipment(
Order $order)
285 $collection = $order->getShipmentCollection();
287 $deliveryId = static::getDeliveryId();
288 if ((
int)$deliveryId == 0)
293 $delivery = Sale\Delivery\Services\Manager::getObjectById($deliveryId);
294 $shipment = $collection->createItem($delivery);
296 $itemCollection = $shipment->getShipmentItemCollection();
298 $system = $collection->getSystemShipment();
299 $systemItemCollection = $system->getShipmentItemCollection();
302 foreach ($systemItemCollection as $shipmentItem)
304 $item = $itemCollection->createItem($shipmentItem->getBasketItem());
305 $item->setQuantity($shipmentItem->getQuantity());
308 $shipment->setField(
'DEDUCTED',
'Y');
321 $paySystemList = Sale\PaySystem\Manager::getListWithRestrictions($payment);
322 foreach ($paySystemList as $paySystem)
324 if ((
int)$paySystem[
'ID'] === (
int)
Sale\PaySystem\Manager::getInnerPaySystemId())
329 return $paySystem[
'ID'];
341 return Sale\Delivery\Services\Manager::getEmptyDeliveryServiceId();
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)