public function checkByShipment(\Bitrix\Sale\Shipment $shipment, array $restrictionParams, $deliveryId = 0) { if (!\Bitrix\Main\Loader::includeModule('iblock')) { return array(); } if (!\Bitrix\Main\Loader::includeModule('catalog')) { return array(); } $productIds = array(); /** @var \Bitrix\Sale\ShipmentItem $shipmentItem */ foreach ($shipment->getShipmentItemCollection() as $shipmentItem) { /** @var \Bitrix\Sale\BasketItem $basketItem */ $basketItem = $shipmentItem->getBasketItem(); if ($basketItem->getField('MODULE') != 'catalog') { continue; } $productId = intval($basketItem->getField('PRODUCT_ID')); $iblockId = (int) \CIBlockElement::getIBlockByID($productId); $info = \CCatalogSKU::getProductInfo($productId, $iblockId); if (!empty($info['ID'])) { $candidate = $info['ID']; } else { $candidate = $productId; } if (!in_array($candidate, $productIds)) { $productIds[] = $candidate; } } $categoriesIds = self::getGroupsIds($productIds); return $this->check($categoriesIds, $restrictionParams, $deliveryId); }
public function checkByShipment(\Bitrix\Sale\Shipment $shipment, array $restrictionParams, $deliveryId = 0) { if (empty($restrictionParams)) { return true; } $siteId = $shipment->getCollection()->getOrder()->getSiteId(); return $this->check($siteId, $restrictionParams, $deliveryId); }
public function checkByShipment(\Bitrix\Sale\Shipment $shipment, array $restrictionParams, $deliveryId = 0) { if (empty($restrictionParams)) { return true; } $weight = $shipment->getWeight(); return $this->check($weight, $restrictionParams, $deliveryId); }
/** * @param \Bitrix\Sale\Shipment $shipment * @param string $jsObjName * @param string $idPrefix * @throws \Bitrix\Main\ArgumentNullException */ public function __construct($shipment, $jsObjName = "", $idPrefix = "") { self::$useStoreControl = Option::get('catalog', 'default_use_store_control', 'N') == 'Y'; $order = $shipment->getCollection()->getOrder(); parent::__construct($order, $jsObjName, $idPrefix); $this->shipment = $shipment; $this->data = array(); }
protected function calculateConcrete(\Bitrix\Sale\Shipment $shipment = null) { $result = new CalculationResult(); $price = $this->config["MAIN"]["PRICE"]; if ($shipment && \Bitrix\Main\Loader::includeModule('currency')) { $rates = new \CCurrencyRates(); $currency = $this->currency; $shipmentCurrency = $shipment->getCollection()->getOrder()->getCurrency(); $price = $rates->convertCurrency($price, $currency, $shipmentCurrency); } $result->setDeliveryPrice(roundEx($price, SALE_VALUE_PRECISION)); $result->setPeriodDescription($this->getPeriodText()); return $result; }
public function checkByShipment(\Bitrix\Sale\Shipment $shipment, array $restrictionParams, $deliveryId = 0) { if (intval($deliveryId) <= 0) { return true; } /** @var \Bitrix\Sale\Order $order */ $order = $shipment->getCollection()->getOrder(); if (!($props = $order->getPropertyCollection())) { return true; } if (!($locationProp = $props->getDeliveryLocation())) { return true; } if (!($locationCode = $locationProp->getValue())) { return true; } return $this->check($locationCode, $restrictionParams, $deliveryId); }
public function checkByShipment(\Bitrix\Sale\Shipment $shipment, array $restrictionParams, $deliveryId = 0) { if (empty($restrictionParams)) { return true; } $result = true; if (!($itemCollection = $shipment->getShipmentItemCollection())) { throw new SystemException("Cant get ShipmentItemCollection"); } $shipmentPrice = $itemCollection->getPrice(); if (\Bitrix\Main\Loader::includeModule('currency')) { $shipmentPrice = \CCurrencyRates::convertCurrency($shipmentPrice, $shipment->getCurrency(), $restrictionParams["CURRENCY"]); } if ($shipmentPrice >= 0) { $result = $this->check($shipmentPrice, $restrictionParams, $deliveryId); } return $result; }
public function checkByShipment(\Bitrix\Sale\Shipment $shipment, array $restrictionParams, $deliveryId = 0) { if (intval($deliveryId) <= 0) { return true; } $paymentsCount = 0; $paySystemId = 0; /** @var \Bitrix\Sale\Payment $payment */ foreach ($shipment->getCollection()->getOrder()->getPaymentCollection() as $payment) { if ($payment->getId() != PaySystemInner::getId()) { $paymentsCount++; $paySystemId = $payment->getPaymentSystemId(); } } if ($paymentsCount <= 0 || $paymentsCount > 1 || $paySystemId <= 0) { return true; } return $this->check($paySystemId, $restrictionParams, $deliveryId); }
public function checkByShipment(\Bitrix\Sale\Shipment $shipment, array $restrictionParams, $deliveryId = 0) { if (empty($restrictionParams)) { return true; } foreach ($shipment->getShipmentItemCollection() as $shipmentItem) { $basketItem = $shipmentItem->getBasketItem(); $dimensions = $basketItem->getField("DIMENSIONS"); if (is_string($dimensions)) { $dimensions = unserialize($dimensions); } if (!is_array($dimensions) || empty($dimensions)) { return true; } if (!$this->check($dimensions, $restrictionParams, $deliveryId)) { return false; } } return true; }
/** * @param \Bitrix\Sale\Shipment|null $shipment * @return CalculationResult * @throws \Bitrix\Main\ArgumentException */ protected function calculateConcrete(\Bitrix\Sale\Shipment $shipment = null) { $result = new CalculationResult(); $result->setDeliveryPrice(roundEx($this->config["MAIN"]["0"], SALE_VALUE_PRECISION)); $order = $shipment->getCollection()->getOrder(); if (!($props = $order->getPropertyCollection())) { return $result; } if (!($locationProp = $props->getDeliveryLocation())) { return $result; } if (!($locationCode = $locationProp->getValue())) { return $result; } $res = \Bitrix\Sale\Location\LocationTable::getList(array('runtime' => array(new \Bitrix\Main\Entity\ReferenceField('PARENT_GROUP', '\\Bitrix\\Sale\\Location\\GroupLocationTable', array('=this.PARENTS.ID' => 'ref.LOCATION_ID'), array("join_type" => 'inner'))), 'filter' => array('=CODE' => $locationCode), 'select' => array('CLOSEST_GROUP_ID' => 'PARENT_GROUP.LOCATION_GROUP_ID'), 'order' => array('PARENTS.DEPTH_LEVEL' => 'desc'), 'limit' => 1)); if ($group = $res->fetch()) { if (isset($this->config["MAIN"][$group['CLOSEST_GROUP_ID']])) { $result->setDeliveryPrice(roundEx(floatval($this->config["MAIN"][$group['CLOSEST_GROUP_ID']]), SALE_VALUE_PRECISION)); } } return $result; }
/** * @param $profileId * @param array $profileConfig * @param \Bitrix\Sale\Shipment $shipment * @return CalculationResult * @throws SystemException * @throws \Bitrix\Main\LoaderException */ public function calculateProfile($profileId, array $profileConfig, \Bitrix\Sale\Shipment $shipment) { global $APPLICATION; $result = new CalculationResult(); $step = 0; $tmp = false; /** @var ShipmentCollection $shipmentCollection */ $shipmentCollection = $shipment->getCollection(); /** @var Order $order */ $order = $shipmentCollection->getOrder(); $shipmentCurrency = $order->getCurrency(); if (!Loader::includeModule('currency')) { throw new SystemException("Can't include module \"Currency\""); } $calculator = $this->getCalcultor(); if ($calculator !== false) { if ($res = call_user_func($calculator, $profileId, $profileConfig["CONFIG"], self::convertNewOrderToOld($shipment), ++$step, $tmp)) { if (is_array($res)) { if ($res["RESULT"] == "OK") { if (isset($res["TEXT"])) { $result->setDescription($res["TEXT"]); } if (isset($res["VALUE"])) { $result->setDeliveryPrice(floatval($res["VALUE"])); } if (isset($res["TRANSIT"])) { $result->setPeriodDescription($res["TRANSIT"]); } } else { if (isset($res["TEXT"]) && strlen($res["TEXT"]) > 0) { $result->addError(new EntityError($res["TEXT"], 'DELIVERY_CALCULATION')); } else { $result->addError(new EntityError(Loc::getMessage('SALE_DLVR_HANDL_AUT_ERROR_CALCULATION'), 'DELIVERY_CALCULATION')); } } } elseif (is_numeric($res)) { $result->setDeliveryPrice(floatval($res)); } } else { if ($ex = $APPLICATION->getException()) { $result->addError(new EntityError($ex->getString(), 'DELIVERY_CALCULATION')); } else { $result->setDeliveryPrice(0); } } if ($result->isSuccess() && $this->currency != $shipmentCurrency) { $result->setDeliveryPrice(\CCurrencyRates::convertCurrency($result->getPrice(), $this->currency, $shipmentCurrency)); } } $result->setDeliveryPrice($result->getPrice() + $this->getMarginPrice($shipment)); return $result; }
/** * @return array */ protected static function getShipmentAvailableFields() { $clearFields = array('STATUS_ID'); $result = array(); $fields = Sale\Shipment::getAvailableFields(); if (!empty($clearFields)) { foreach ($fields as $field) { if (!in_array($field, $clearFields)) { $result[] = $field; } } } return $result; }
/** * Modify shipment collection. * * @param string $action Action code. * @param Shipment $shipment Shipment. * @param null|string $name Field name. * @param null|string|int|float $oldValue Old value. * @param null|string|int|float $value New value. * @return bool * * @throws Main\NotImplementedException * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentOutOfRangeException * @throws \Bitrix\Main\NotSupportedException * @throws \Exception */ public function onShipmentCollectionModify($action, Shipment $shipment, $name = null, $oldValue = null, $value = null) { global $USER; $result = new Result(); if ($action == EventActions::DELETE) { if ($this->getField('DELIVERY_ID') == $shipment->getDeliveryId()) { /** @var ShipmentCollection $shipmentCollection */ if (!($shipmentCollection = $shipment->getCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found'); } $foundShipment = false; /** @var Shipment $entityShipment */ foreach ($shipmentCollection as $entityShipment) { if ($entityShipment->isSystem()) { continue; } if (intval($entityShipment->getField('DELIVERY_ID')) > 0) { $foundShipment = true; $this->setFieldNoDemand('DELIVERY_ID', $entityShipment->getField('DELIVERY_ID')); break; } } if (!$foundShipment && !$shipment->isSystem()) { /** @var Shipment $systemShipment */ if (($systemShipment = $shipmentCollection->getSystemShipment()) && intval($systemShipment->getField('DELIVERY_ID')) > 0) { $this->setFieldNoDemand('DELIVERY_ID', $systemShipment->getField('DELIVERY_ID')); } } } } if ($action != EventActions::UPDATE) { return $result; } // PRICE_DELIVERY, ALLOW_DELIVERY, DEDUCTED, MARKED // CANCELED, DELIVERY_ID if ($name == "ALLOW_DELIVERY") { if ($this->isCanceled()) { $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_ALLOW_DELIVERY_ORDER_CANCELED'), 'SALE_ORDER_ALLOW_DELIVERY_ORDER_CANCELED')); return $result; } $r = $shipment->deliver(); if ($r->isSuccess()) { $event = new Main\Event('sale', EventActions::EVENT_ON_SHIPMENT_DELIVER, array('ENTITY' => $shipment)); $event->send(); } else { $result->addErrors($r->getErrors()); } if (Configuration::getProductReservationCondition() == Configuration::RESERVE_ON_ALLOW_DELIVERY) { if ($value == "Y") { /** @var Result $r */ $r = $shipment->tryReserve(); if (!$r->isSuccess()) { $shipment->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $shipment->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $error) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error; } $shipment->setField('REASON_MARKED', $oldErrorText); } $result->addErrors($r->getErrors()); } } else { if (!$shipment->isShipped()) { /** @var Result $r */ $r = $shipment->tryUnreserve(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } if (!$result->isSuccess()) { return $result; } } if ($oldValue == "N") { $orderStatus = Config\Option::get('sale', 'status_on_allow_delivery', ''); if (strval($orderStatus) != '') { if ($USER && $USER->isAuthorized()) { $statusesList = OrderStatus::getAllowedUserStatuses($USER->getID(), $this->getField('STATUS_ID')); } else { $statusesList = OrderStatus::getAllStatuses(); } if ($this->getField('STATUS_ID') != $orderStatus && array_key_exists($orderStatus, $statusesList)) { /** @var Result $r */ $r = $this->setField('STATUS_ID', $orderStatus); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } } } } if (Configuration::needShipOnAllowDelivery() && $value == "Y") { $shipment->setField("DEDUCTED", "Y"); } /** @var ShipmentCollection $shipmentCollection */ if (!($shipmentCollection = $this->getShipmentCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found'); } if ($shipmentCollection->isAllowDelivery() && $this->getField('ALLOW_DELIVERY') == 'N') { $this->setFieldNoDemand('DATE_ALLOW_DELIVERY', new Type\DateTime()); } $this->setFieldNoDemand('ALLOW_DELIVERY', $shipmentCollection->isAllowDelivery() ? "Y" : "N"); } elseif ($name == "DEDUCTED") { if ($this->isCanceled()) { $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_SHIPMENT_ORDER_CANCELED'), 'SALE_ORDER_SHIPMENT_ORDER_CANCELED')); return $result; } if (Configuration::getProductReservationCondition() == Configuration::RESERVE_ON_SHIP) { if ($value == "Y") { /** @var Result $r */ $r = $shipment->tryReserve(); if (!$r->isSuccess()) { $shipment->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $shipment->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $error) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error; } $shipment->setField('REASON_MARKED', $oldErrorText); } $result->addErrors($r->getErrors()); return $result; } } else { $shipment->tryUnreserve(); } } if ($value == "Y") { /** @var Result $r */ $r = $shipment->tryShip(); if (!$r->isSuccess()) { $shipment->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $shipment->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $error) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error; } $shipment->setField('REASON_MARKED', $oldErrorText); } $result->addErrors($r->getErrors()); return $result; } } elseif ($oldValue == 'Y') { /** @var Result $r */ $r = $shipment->tryUnship(); if (!$r->isSuccess()) { /** @var Result $resultShipment */ $resultShipment = $shipment->setField('MARKED', 'Y'); if (!$resultShipment->isSuccess()) { $result->addErrors($r->getErrors()); } if (is_array($r->getErrorMessages())) { $oldErrorText = $shipment->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $error) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error; } /** @var Result $resultShipment */ $resultShipment = $shipment->setField('REASON_MARKED', $oldErrorText); if (!$resultShipment->isSuccess()) { $result->addErrors($r->getErrors()); } } $result->addErrors($r->getErrors()); return $result; } } /** @var ShipmentCollection $shipmentCollection */ $shipmentCollection = $shipment->getCollection(); $this->setFieldNoDemand('DEDUCTED', $shipmentCollection->isShipped() ? "Y" : "N"); if ($shipmentCollection->isShipped()) { if (strval($shipment->getField('DATE_DEDUCTED')) != '') { $this->setFieldNoDemand('DATE_DEDUCTED', $shipment->getField('DATE_DEDUCTED')); } if (strval($shipment->getField('EMP_DEDUCTED_ID')) != '') { $this->setFieldNoDemand('EMP_DEDUCTED_ID', $shipment->getField('EMP_DEDUCTED_ID')); } } } elseif ($name == "MARKED") { if ($value == "Y") { /** @var Result $r */ $r = $this->setField('MARKED', 'Y'); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } elseif ($name == "REASON_MARKED") { if (!empty($value)) { $orderReasonMarked = $this->getField('REASON_MARKED'); if (is_array($value)) { $newOrderReasonMarked = ''; foreach ($value as $err) { $newOrderReasonMarked .= (strval($newOrderReasonMarked) != '' ? "\n" : "") . $err; } } else { $newOrderReasonMarked = $value; } /** @var Result $r */ $r = $this->setField('REASON_MARKED', $orderReasonMarked . (strval($orderReasonMarked) != '' ? "\n" : "") . $newOrderReasonMarked); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } elseif ($name == "BASE_PRICE_DELIVERY") { if ($this->isCanceled()) { $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_PRICE_DELIVERY_ORDER_CANCELED'), 'SALE_ORDER_PRICE_DELIVERY_ORDER_CANCELED')); return $result; } /** @var ShipmentCollection $shipmentCollection */ if (!($shipmentCollection = $shipment->getCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found'); } $discount = $this->getDiscount(); $discount->setCalculateShipments($shipment); $r = $shipment->setField('PRICE_DELIVERY', $value); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } elseif ($name == "PRICE_DELIVERY") { if ($this->isCanceled()) { $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_PRICE_DELIVERY_ORDER_CANCELED'), 'SALE_ORDER_PRICE_DELIVERY_ORDER_CANCELED')); return $result; } /** @var ShipmentCollection $shipmentCollection */ if (!($shipmentCollection = $shipment->getCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found'); } $this->setFieldNoDemand("PRICE_DELIVERY", $this->getField("PRICE_DELIVERY") - $oldValue + $value); /** @var Result $r */ $r = $this->setField("PRICE", $this->getField("PRICE") - $oldValue + $value); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } elseif ($name == "DELIVERY_ID") { if ($shipment->isSystem() || intval($shipment->getField('DELIVERY_ID')) <= 0) { return $result; } $this->setFieldNoDemand('DELIVERY_ID', $shipment->getField('DELIVERY_ID')); } return $result; }
/** * @param Shipment $shipment * @return ShipmentItemCollection */ public static function load(Shipment $shipment) { /** @var ShipmentItemCollection $shipmentItemCollection */ $shipmentItemCollection = new static(); $shipmentItemCollection->shipment = $shipment; if ($shipment->getId() > 0) { $shipmentItemList = ShipmentItem::loadForShipment($shipment->getId()); /** @var ShipmentItem $shipmentItem */ foreach ($shipmentItemList as $shipmentItem) { $shipmentItem->setCollection($shipmentItemCollection); $shipmentItemCollection->addItem($shipmentItem); } } return $shipmentItemCollection; }
$val["DISCOUNT_RATION_PERCENT"] = round($val["PRICE"] * 100 / $priceTotal, 5); $val["DISCOUNT_RATION_VALUE"] = round($discount * $val["DISCOUNT_RATION_PERCENT"] / 100, 5); $val["PRICE"] -= $val["DISCOUNT_RATION_VALUE"]; $arBasket[$key] = $val; } return $arBasket; } if (CModule::IncludeModule("sale")) { if ($arOrder = CSaleOrder::GetByID($ORDER_ID)) { if (isset($_REQUEST['SHIPMENT_ID']) && intval($_REQUEST['SHIPMENT_ID']) > 0) { $shipmentId = $_REQUEST['SHIPMENT_ID']; $res = \Bitrix\Sale\Internals\ShipmentTable::getList(array('select' => array('PRICE_DELIVERY'), 'filter' => array('ID' => $_REQUEST['SHIPMENT_ID']))); $data = $res->fetch(); $arOrder['PRICE_DELIVERY'] = $data['PRICE_DELIVERY']; } $shipmentRes = \Bitrix\Sale\Shipment::getList(array('select' => array('DATE_ALLOW_DELIVERY', 'EMP_ALLOW_DELIVERY_ID', 'DATE_DEDUCTED', 'EMP_ALLOW_DELIVERY_ID', 'TRACKING_NUMBER', 'DELIVERY_DOC_NUM', 'DELIVERY_DOC_DATE'), 'filter' => array('ORDER_ID' => $arOrder['ID'], 'SYSTEM' => 'N'), 'order' => array('ID' => 'DESC'), 'limit' => 1)); if ($shipmentData = $shipmentRes->fetch()) { $arOrder = array_merge($arOrder, $shipmentData); } $rep_file_name = GetRealPath2Report($doc . ".php"); if (strlen($rep_file_name) <= 0) { ShowError("PRINT TEMPLATE NOT FOUND"); die; } $arOrderProps = array(); $dbOrderPropVals = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $ORDER_ID), false, false, array("ID", "CODE", "VALUE", "ORDER_PROPS_ID", "PROP_TYPE")); while ($arOrderPropVals = $dbOrderPropVals->Fetch()) { $arCurOrderPropsTmp = CSaleOrderProps::GetRealValue($arOrderPropVals["ORDER_PROPS_ID"], $arOrderPropVals["CODE"], $arOrderPropVals["PROP_TYPE"], $arOrderPropVals["VALUE"], LANGUAGE_ID); foreach ($arCurOrderPropsTmp as $key => $value) { $arOrderProps[$key] = $value; }
protected static function calculateShipmentPrice(\Bitrix\Sale\Shipment $shipment) { $result = 0; foreach ($shipment->getShipmentItemCollection() as $shipmentItem) { /** @var \Bitrix\Sale\BasketItem $basketItem */ $basketItem = $shipmentItem->getBasketItem(); $result += $basketItem->getPrice(); } return $result; }
/** * @internal * @param Shipment $parentShipment * @param Shipment $childShipment * @return Result * @throws Main\ArgumentOutOfRangeException */ public function cloneShipment(Shipment $parentShipment, Shipment $childShipment) { foreach (static::getClonedFields() as $fieldName) { /** @var Result $r */ $childShipment->setFieldNoDemand($fieldName, $parentShipment->getField($fieldName)); } $childShipment->setExtraServices($parentShipment->getExtraServices()); $childShipment->setStoreId($parentShipment->getStoreId()); return new Result(); }
public function processAdditionalInfoShipmentEdit(Shipment $shipment, array $requestData) { if (empty($requestData['REQUEST_SELF']) || $requestData['REQUEST_SELF'] != 'Y') { return null; } $shipmentId = $shipment->getId(); if (intval($shipmentId) <= 0) { return null; } $dt = new \Bitrix\Main\Type\DateTime(); $arResult = CSaleDeliveryHandler::executeAction(\CSaleDelivery::getCodeById($shipment->getDeliveryId()), 'REQUEST_SELF', \CAllSaleDelivery::convertOrderNewToOld($shipment)); if (!$arResult) { return null; } $res = \Bitrix\Sale\Internals\OrderDeliveryReqTable::add(array("SHIPMENT_ID" => $shipmentId, "ORDER_ID" => $shipment->getCollection()->getOrder()->getId(), "DATE_REQUEST" => $dt, "PARAMS" => array("TYPE" => "REQUEST_SELF", "RESULT" => $arResult))); if (!$res->isSuccess()) { return null; } if (isset($arResult["TRACKING_NUMBER"])) { $shipment->setField("TRACKING_NUMBER", $arResult["TRACKING_NUMBER"]); } if (isset($arResult["DELIVERY_DOC_NUM"])) { $shipment->setField("DELIVERY_DOC_NUM", $arResult["DELIVERY_DOC_NUM"]); $shipment->setField("DELIVERY_DOC_DATE", $dt); } return $shipment; }
public static function calculate(Shipment $shipment) { $delivery = self::getService($shipment->getDeliveryId()); return $delivery->calculate($shipment); }
/** * @param \Bitrix\Sale\Shipment $shipment * @throws Main\NotSupportedException */ public static function setShipmentByDefaultValues(&$shipment) { /** @var \Bitrix\Sale\ShipmentCollection $shipmentCollection */ $shipmentCollection = $shipment->getCollection(); $systemShipment = $shipmentCollection->getSystemShipment(); $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection(); /** @var \Bitrix\Sale\ShipmentItemCollection $shipmentItemCollection */ $shipmentItemCollection = $shipment->getShipmentItemCollection(); /** @var \Bitrix\Sale\ShipmentItem $systemShipmentItem */ foreach ($systemShipmentItemCollection as $systemShipmentItem) { if ($systemShipmentItem->getQuantity() <= 0) { continue; } $basketItem = $systemShipmentItem->getBasketItem(); $shipmentItem = $shipmentItemCollection->createItem($basketItem); $shipmentItem->setField('QUANTITY', $systemShipmentItem->getQuantity()); } $shipment->setField('CUSTOM_PRICE_DELIVERY', 'N'); $shipment->setField('DELIVERY_ID', $systemShipment->getField('DELIVERY_ID')); $shipment->setField('COMPANY_ID', $systemShipment->getField('COMPANY_ID')); $shipment->setField('DELIVERY_NAME', $systemShipment->getField('DELIVERY_NAME')); $shipment->setExtraServices($systemShipment->getExtraServices()); $shipment->setStoreId($systemShipment->getStoreId()); $price = \Bitrix\Sale\Helpers\Admin\Blocks\OrderShipment::getDeliveryPrice($shipment); $shipment->setField('BASE_PRICE_DELIVERY', $price); }
/** * @param Shipment $shipment * @return array Old order. * @throws \Bitrix\Main\ArgumentNullException */ public static function convertOrderNewToOld(\Bitrix\Sale\Shipment $shipment) { /** @var \Bitrix\Sale\ShipmentCollection $shipmentCollection */ $shipmentCollection = $shipment->getCollection(); /** @var \Bitrix\Sale\Order $newOrder */ $newOrder = $shipmentCollection->getOrder(); $props = $newOrder->getPropertyCollection(); $oldOrder = array(); if (intval($newOrder->getId()) > 0) { $oldOrder["ID"] = $newOrder->getId(); } /** @var \Bitrix\Sale\Basket $basket */ if ($collection = $shipment->getShipmentItemCollection()) { $oldOrder["PRICE"] = $collection->getPrice(); } $oldOrder["WEIGHT"] = 0; $oldOrder["LOCATION_FROM"] = \Bitrix\Main\Config\Option::get('sale', 'location', "", $newOrder->getSiteId()); $oldOrder["SITE_ID"] = $newOrder->getSiteId(); $oldOrder["PERSON_TYPE_ID"] = $newOrder->getPersonTypeId(); $oldOrder["CURRENCY"] = $newOrder->getCurrency(); $loc = $props->getDeliveryLocation(); $oldOrder["LOCATION_TO"] = !!$loc ? $loc->getValue() : ""; $loc = $props->getDeliveryLocationZip(); $oldOrder["LOCATION_ZIP"] = !!$loc ? $loc->getValue() : ""; $oldOrder["ITEMS"] = array(); /** @var \Bitrix\Sale\ShipmentItem $shipmentItem */ foreach ($shipment->getShipmentItemCollection() as $shipmentItem) { $basketItem = $shipmentItem->getBasketItem(); if (!$basketItem) { continue; } $itemFieldValues = $basketItem->getFieldValues(); $itemFieldValues["QUANTITY"] = $shipmentItem->getField("QUANTITY"); if (!empty($itemFieldValues["DIMENSIONS"]) && is_string($itemFieldValues["DIMENSIONS"])) { $itemFieldValues["DIMENSIONS"] = unserialize($itemFieldValues["DIMENSIONS"]); } $oldOrder["ITEMS"][] = $itemFieldValues; $itemWeight = floatval($basketItem->getField("WEIGHT")); if ($itemWeight > 0) { $oldOrder["WEIGHT"] += $itemWeight * floatval($basketItem->getField("QUANTITY")); } } return $oldOrder; }
/** * @param Shipment $shipment * @return array */ private static function getProviderBasketFromShipment(Shipment $shipment) { $shipmentItemCollection = $shipment->getShipmentItemCollection(); $basketList = static::getBasketFromShipmentItemCollection($shipmentItemCollection); $basketProviderMap = static::createProviderBasketMap($basketList, array('QUANTITY', 'PRODUCT_ID')); $basketProviderList = static::redistributeToProviders($basketProviderMap); return $basketProviderList; }