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; } $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 (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; }
protected static function convertNewOrderToOld(\Bitrix\Sale\Shipment $shipment) { /** @var ShipmentCollection $shipmentCollection */ $shipmentCollection = $shipment->getCollection(); /** @var Order $newOrder */ $newOrder = $shipmentCollection->getOrder(); $props = $newOrder->getPropertyCollection(); $oldOrder = array(); /** @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(); $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; }
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; }
/** * @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 */ 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; }