/** * @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; }
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; }
/** * @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; }
protected function calculateConcrete(Shipment $shipment) { $result = new CalculationResult(); $result->addError(new EntityError(Loc::getMessage("SALE_DLVR_HANDL_GROUP_ERROR_CALCULATION"), 'DELIVERY_CALCULATION')); return $result; }