コード例 #1
0
ファイル: persontype.php プロジェクト: DarneoStudio/bitrix
 /**
  * @param OrderBase $order
  * @return Entity\Result
  */
 public static function doCalculate(OrderBase $order)
 {
     $result = new Result();
     if ($order->getPersonTypeId() !== null) {
         if (!($personTypeList = static::load($order->getSiteId(), $order->getPersonTypeId()))) {
             $result->addError(new Entity\EntityError(GetMessage('SKGP_PERSON_TYPE_NOT_FOUND'), 'PERSON_TYPE_ID'));
         }
         return $result;
     }
     if (($personTypeList = static::load($order->getSiteId())) && !empty($personTypeList) && is_array($personTypeList)) {
         $firstPersonType = reset($personTypeList);
         $order->setPersonTypeId($firstPersonType["ID"]);
     } else {
         $result->addError(new Entity\EntityError(GetMessage('SKGP_PERSON_TYPE_EMPTY'), 'PERSON_TYPE_ID'));
     }
     return $result;
 }
コード例 #2
0
 /**
  * @return Result
  */
 public function calculateDelivery()
 {
     /** @var Result $result */
     $result = new Result();
     $shipmentListResult = array();
     /** @var Shipment $shipment */
     foreach ($this->collection as $shipment) {
         if ($shipment->isSystem() || $shipment->getDeliveryId() == 0) {
             continue;
         }
         if ($shipment->isCustomPrice()) {
             //				$shipmentListResult[] = array(
             //					'SHIPMENT_ITEM' => $shipment,
             //					'PRICE' => $shipment->getPrice(),
             //					'AVAILABLE' => true,
             //				);
             //				continue;
             $priceDelivery = $shipment->getPrice();
             $shipment->setField('BASE_PRICE_DELIVERY', $priceDelivery);
         } else {
             $deliveryCalculate = $shipment->calculateDelivery();
             if (!$deliveryCalculate->isSuccess()) {
                 $result->addErrors($deliveryCalculate->getErrors());
                 continue;
             }
             $deliveryCalculateData = $deliveryCalculate->getData();
             if (!isset($deliveryCalculateData['AVAILABLE'])) {
                 $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_DELIVERY_SERVICE_NOT_AVAILABLE'), 'DELIVERY_SERVICE_NOT_AVAILABLE'));
                 continue;
             }
             if ($deliveryCalculate->getPrice() < 0) {
                 $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_SHIPMENT_WRONG_DELIVERY_PRICE'), 'WRONG_DELIVERY_PRICE'));
                 continue;
             }
             $shipment->setField('BASE_PRICE_DELIVERY', $deliveryCalculate->getPrice());
             //			$shipmentListResult[] = array(
             //				'SHIPMENT_ITEM' => $shipment,
             //				'PRICE' => $deliveryCalculate->getPrice(),
             //				'AVAILABLE' => $deliveryCalculateData['AVAILABLE'],
             //			);
         }
     }
     // event OnSaleCalculateOrderDelivery
     return $result;
 }
コード例 #3
0
 function setValuesFromPost($post, $files)
 {
     $post = Input\File::getPostWithFiles($post, $files);
     $result = new Result();
     /** @var PropertyValue $property */
     foreach ($this->collection as $property) {
         $r = $property->setValueFromPost($post);
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     }
     return $result;
 }
コード例 #4
0
ファイル: tax.php プロジェクト: Satariall/izurit
 /**
  * @return Result
  */
 public function save()
 {
     $result = new Result();
     /** @var Order $order */
     $order = $this->getOrder();
     //DoSaveOrderTax
     \CSaleTax::DoSaveOrderTax($order->getId(), $this->getTaxList(), $errors = array());
     if (!empty($errors) && is_array($errors)) {
         foreach ($errors as $error) {
             $result->addError(new EntityError($error));
         }
     }
     return $result;
 }
コード例 #5
0
 /**
  * Data synchronization basket and shipment
  *
  * @internal
  *
  * @param Sale\ShipmentCollection $shipmentCollection		Entity shipment collection.
  * @param Sale\Basket $basket								Entity basket.
  *
  * @return Sale\Result
  * @throws \Bitrix\Main\ArgumentTypeException
  * @throws \Bitrix\Main\ObjectNotFoundException
  */
 public static function syncShipmentCollectionAndBasket(Sale\ShipmentCollection $shipmentCollection, Sale\Basket $basket)
 {
     $result = new Sale\Result();
     if (count($shipmentCollection) > 2) {
         return $result;
     }
     /** @var Sale\Order $order */
     if (!($order = $shipmentCollection->getOrder())) {
         throw new Main\ObjectNotFoundException('Entity "Order" not found');
     }
     $baseShipment = null;
     $shipmentCollection->setMathActionOnly(true);
     if (count($shipmentCollection) == 1 && $shipmentCollection->isExistsSystemShipment()) {
         /** @var Sale\Shipment $systemShipment */
         if (!($systemShipment = $shipmentCollection->getSystemShipment())) {
             throw new Main\ObjectNotFoundException('Entity system "Shipment" not found');
         }
         $shipment = $shipmentCollection->createItem();
         $r = $shipmentCollection->cloneShipment($systemShipment, $shipment);
         if (!$r->isSuccess()) {
             return $r;
         }
     }
     /** @var Sale\Shipment $shipment */
     foreach ($shipmentCollection as $shipment) {
         if ($shipment->isSystem() || $shipment->isShipped()) {
             continue;
         }
         /** @var Sale\BasketItem $basketItem */
         foreach ($basket as $basketItem) {
             $shipmentItemCollection = $shipment->getShipmentItemCollection();
             if (!($shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode()))) {
                 $shipmentItem = $shipmentItemCollection->createItem($basketItem);
             }
             if (!$shipmentItem) {
                 continue;
             }
             /** @var Sale\Result $r */
             $r = $shipmentItem->setQuantity($basketItem->getQuantity());
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
         }
         break;
     }
     $shipmentCollection->setMathActionOnly(false);
     return $result;
 }
コード例 #6
0
ファイル: basketitem.php プロジェクト: andy-profi/bxApiDocs
 /**
  *
  */
 public function delete()
 {
     $result = new Result();
     /** @var Basket $basket */
     if (!($basket = $this->getCollection())) {
         throw new ObjectNotFoundException('Entity "Basket" not found');
     }
     /** @var Order $order */
     if ($order = $basket->getOrder()) {
         /** @var ShipmentCollection $shipmentCollection */
         if ($shipmentCollection = $order->getShipmentCollection()) {
             /** @var Shipment $shipment */
             foreach ($shipmentCollection as $shipment) {
                 if ($shipment->isSystem()) {
                     continue;
                 }
                 /** @var ShipmentItemCollection $shipmentItemCollection */
                 if ($shipmentItemCollection = $shipment->getShipmentItemCollection()) {
                     if ($shipmentItemCollection->getItemByBasketCode($this->getBasketCode()) && $shipment->isShipped()) {
                         $result->addError(new ResultError(Loc::getMessage('SALE_BASKET_ITEM_REMOVE_IMPOSSIBLE_BECAUSE_SHIPPED', array('#PRODUCT_NAME#' => $this->getField('NAME'))), 'SALE_BASKET_ITEM_REMOVE_IMPOSSIBLE_BECAUSE_SHIPPED'));
                         return $result;
                     }
                 }
             }
         }
     }
     $r = $this->setField("QUANTITY", 0);
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
         return $result;
     }
     $bundleCollection = null;
     if ($this->isBundleParent()) {
         /** @var Basket $bundleCollection */
         $bundleCollection = $this->getBundleCollection();
     }
     if (!$this->isBundleChild()) {
         /** @var Result $r */
         $r = parent::delete();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
             return $result;
         }
     }
     if ($bundleCollection !== null) {
         /** @var BasketItem $bundleBasketItem */
         foreach ($bundleCollection as $bundleBasketItem) {
             /** @var Result $r */
             $r = $bundleBasketItem->delete();
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
         }
     }
     return $result;
 }
コード例 #7
0
 /**
  * @param Sale\Order $order
  *
  * @return array
  */
 public static function getOrderFields(Sale\Order $order)
 {
     $result = new Sale\Result();
     $paymentSystemId = false;
     $deliveryId = false;
     /** @var Sale\PaymentCollection $paymentCollection */
     if ($paymentCollection = $order->getPaymentCollection()) {
         /** @var Sale\Payment $payment */
         if ($payment = $paymentCollection->rewind()) {
             $paymentSystemId = $payment->getPaymentSystemId();
         }
     }
     /** @var Sale\ShipmentCollection $shipe */
     if ($shipmentCollection = $order->getShipmentCollection()) {
         /** @var Sale\Shipment $shipment */
         foreach ($shipmentCollection as $shipment) {
             if ($shipment->getDeliveryId() > 0) {
                 $deliveryId = $shipment->getDeliveryId();
                 break;
             }
         }
     }
     $fields = array("SITE_ID" => $order->getSiteId(), "LID" => $order->getSiteId(), "PERSON_TYPE_ID" => $order->getPersonTypeId(), "PRICE" => $order->getPrice(), "CURRENCY" => $order->getCurrency(), "USER_ID" => $order->getUserId(), "PAY_SYSTEM_ID" => $paymentSystemId, "PRICE_DELIVERY" => $order->getDeliveryPrice(), "DELIVERY_ID" => $deliveryId, "DISCOUNT_VALUE" => $order->getDiscountPrice(), "TAX_VALUE" => $order->getTaxValue(), "TRACKING_NUMBER" => $order->getField('TRACKING_NUMBER'), "PAYED" => $order->getField('PAYED'), "CANCELED" => $order->getField('CANCELED'), "STATUS_ID" => $order->getField('STATUS_ID'), "RESERVED" => $order->getField('RESERVED'));
     $orderFields = static::convertOrderToArray($order);
     if (is_array($orderFields)) {
         $orderFields = $fields + $orderFields;
         $orderFields = static::convertDateFieldsToOldFormat($orderFields);
     }
     $result->setData(array('FIELDS' => $fields, 'ORDER_FIELDS' => $orderFields));
     return $result;
 }
コード例 #8
0
ファイル: order.php プロジェクト: akniyev/itprom_dobrohost
 /**
  * @return Result
  */
 public function verify()
 {
     $result = new Result();
     /** @var Basket $basket */
     if ($basket = $this->getBasket()) {
         $r = $basket->verify();
         if (!$r->isSuccess()) {
             if ($result instanceof ResultWarning) {
                 $result->addWarnings($r->getErrors());
             } else {
                 $result->addErrors($r->getErrors());
             }
         }
     }
     /** @var PaymentCollection $paymentCollection */
     if ($paymentCollection = $this->getPaymentCollection()) {
         $r = $paymentCollection->verify();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     }
     /** @var ShipmentCollection $shipmentCollection */
     if ($shipmentCollection = $this->getShipmentCollection()) {
         $r = $shipmentCollection->verify();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     }
     return $result;
 }
コード例 #9
0
 /**
  * Convert coupon for saving in order.
  *
  * @param string|array $coupon			Coupon.
  * @param int $discount					Order discount id.
  * @return Sale\Result
  */
 protected static function convertCoupon($coupon, $discount)
 {
     $result = new Sale\Result();
     if (!is_array($coupon)) {
         $couponData = Sale\DiscountCouponsManager::getEnteredCoupon($coupon, true);
         if (empty($couponData)) {
             $result->addError(new Main\Entity\EntityError(Loc::getMessage('BX_SALE_DISCOUNT_ERR_COUPON_NOT_FOUND'), self::ERROR_ID));
             return $result;
         }
         $coupon = array('COUPON' => $couponData['COUPON'], 'TYPE' => $couponData['TYPE'], 'COUPON_ID' => $couponData['ID'], 'DATA' => $couponData);
         unset($couponData);
     }
     $coupon['ORDER_DISCOUNT_ID'] = $discount;
     $coupon['ID'] = 0;
     $orderCouponId = $coupon['COUPON'];
     if (!isset(self::$couponsCache[$orderCouponId])) {
         self::$couponsCache[$orderCouponId] = $coupon;
     }
     $result->setId($orderCouponId);
     $result->setData($coupon);
     unset($coupon, $orderCouponId);
     return $result;
 }
コード例 #10
0
ファイル: providerbase.php プロジェクト: Satariall/izurit
 /**
  * @param Shipment $shipment
  * @return Result
  * @throws NotSupportedException
  */
 public static function deliverShipment(Shipment $shipment)
 {
     global $APPLICATION;
     $result = new Result();
     $needDeliver = $shipment->needDeliver();
     if ($needDeliver === null || $needDeliver === false && $shipment->getId() <= 0) {
         return $result;
     }
     $resultList = array();
     $shipmentItemCollection = $shipment->getShipmentItemCollection();
     $basketList = static::getBasketFromShipmentItemCollection($shipmentItemCollection);
     $basketProviderMap = static::createProviderBasketMap($basketList, array('ORDER_ID', 'USER_ID', 'QUANTITY', 'PAID'));
     $basketProviderList = static::redistributeToProviders($basketProviderMap);
     if (!empty($basketProviderList)) {
         foreach ($basketProviderList as $provider => $providerBasketItemList) {
             if ($provider instanceof Provider) {
                 throw new NotSupportedException('provider not supported');
             } elseif ($provider && array_key_exists("IBXSaleProductProvider", class_implements($provider))) {
                 foreach ($providerBasketItemList as $providerBasketItem) {
                     if ($providerBasketItem['BASKET_ITEM']->isBundleParent()) {
                         continue;
                     }
                     if (!$providerBasketItem['BASKET_ITEM']->isEmptyItem()) {
                         $data = array("PRODUCT_ID" => $providerBasketItem["PRODUCT_ID"], "USER_ID" => $providerBasketItem["USER_ID"], "PAID" => $providerBasketItem["PAID"], "ORDER_ID" => $providerBasketItem["ORDER_ID"], "BASKET_ID" => $providerBasketItem['BASKET_ID']);
                         $APPLICATION->ResetException();
                         $resultProductData = $provider::DeliverProduct($data);
                         if ($ex = $APPLICATION->GetException()) {
                             $result->addError(new ResultError($ex->GetString(), $ex->GetID()));
                         }
                         if (!empty($resultProductData) && is_array($resultProductData)) {
                             $resultProductData['ORDER_ID'] = $providerBasketItem['ORDER_ID'];
                         }
                     } else {
                         $resultProductData = true;
                     }
                     $resultList[$providerBasketItem['BASKET_CODE']] = $resultProductData;
                 }
             } else {
                 foreach ($providerBasketItemList as $providerBasketItem) {
                     $resultProductData = \CSaleBasket::ExecuteCallbackFunction($providerBasketItem['CALLBACK_FUNC'], $providerBasketItem['MODULE'], $providerBasketItem['PRODUCT_ID'], $providerBasketItem['USER_ID'], $providerBasketItem["PAID"], $providerBasketItem['ORDER_ID'], $providerBasketItem["QUANTITY"]);
                     $basketCode = $providerBasketItem['BASKET_ITEM']->getBasketCode();
                     if (!empty($resultProductData) && is_array($resultProductData)) {
                         $resultProductData['ORDER_ID'] = $providerBasketItem['ORDER_ID'];
                     }
                     $resultList[$basketCode] = $resultProductData;
                 }
             }
         }
         if (!empty($resultList) && is_array($resultList)) {
             foreach ($resultList as $basketCode => $resultData) {
                 if ($resultData && !empty($resultData) && is_array($resultData)) {
                     $resultData["REMAINING_ATTEMPTS"] = defined("SALE_PROC_REC_ATTEMPTS") ? SALE_PROC_REC_ATTEMPTS : 3;
                     $resultData["SUCCESS_PAYMENT"] = "Y";
                     // TODO: recurringID
                     /*
                     if ($recurringID > 0)
                     	\CSaleRecurring::Update($recurringID, $resultData);
                     else
                     	\CSaleRecurring::Add($resultData);
                     */
                 }
                 /*
                 elseif ($recurringID > 0)
                 {
                 	\CSaleRecurring::Delete($recurringID);
                 }
                 */
             }
         }
     }
     if (!empty($resultList)) {
         $result->setData($resultList);
     }
     return $result;
 }
コード例 #11
0
 /**
  * @param array $values
  * @return Result
  * @throws Main\ArgumentOutOfRangeException
  * @throws \Exception
  */
 public function setBarcodeQuantityFromArray(array $values)
 {
     $result = new Result();
     $requestBarcodeList = static::getBarcodeListFromArray($values);
     $plusList = array();
     $oldQuantityList = $this->getAllBarcodeList();
     foreach ($requestBarcodeList as $storeId => $barcodeDat) {
         foreach ($barcodeDat as $barcodeValue => $barcode) {
             if (isset($oldQuantityList[$storeId][$barcodeValue]) && $oldQuantityList[$storeId][$barcodeValue]['ID'] == $barcode['ID']) {
                 $oldBarcode = $oldQuantityList[$storeId][$barcodeValue];
                 if ($barcode['QUANTITY'] == $oldBarcode['QUANTITY']) {
                     continue;
                 } elseif ($barcode['QUANTITY'] < $oldBarcode['QUANTITY']) {
                     /** @var ShipmentItemStore $item */
                     $item = $this->getItemById($oldBarcode['ID']);
                     if ($item) {
                         $item->setField('QUANTITY', $barcode['QUANTITY']);
                     }
                 } else {
                     $plusList[$barcodeValue] = array('ID' => $barcode['ID'], 'QUANTITY' => $barcode['QUANTITY']);
                 }
             }
         }
     }
     foreach ($plusList as $barcode) {
         $item = $this->getItemById($barcode['ID']);
         if ($item) {
             /** @var Result $r */
             $r = $item->setField('QUANTITY', $barcode['QUANTITY']);
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
         }
     }
     return $result;
 }
コード例 #12
0
 /**
  * @param $userId
  * @return Sale\Result
  */
 public static function onUserBudgetSave($userId)
 {
     $result = new Sale\Result();
     $pool = static::getUserBudgetPool($userId);
     foreach ($pool->get() as $key => $budgetDat) {
         $orderId = null;
         $paymentId = null;
         if (isset($budgetDat['ORDER']) && $budgetDat['ORDER'] instanceof Sale\OrderBase) {
             $orderId = $budgetDat['ORDER']->getId();
         }
         if (isset($budgetDat['PAYMENT']) && $budgetDat['PAYMENT'] instanceof Sale\Payment) {
             $paymentId = $budgetDat['PAYMENT']->getId();
         }
         //			if ($budgetDat['TYPE'] == Internals\UserBudgetPool::BUDGET_TYPE_ORDER_PAY_PART
         //				|| $budgetDat['TYPE'] == Internals\UserBudgetPool::BUDGET_TYPE_ORDER_PAY)
         //			{
         //				if (!\CSaleUserAccount::Pay($userId, ($budgetDat['SUM'] * -1), $budgetDat['CURRENCY'], $orderId, false, $paymentId))
         //				{
         //					$result->addError( new ResultError(Loc::getMessage("SALE_PROVIDER_USER_BUDGET_".$budgetDat['TYPE']."_ERROR"), "SALE_PROVIDER_USER_BUDGET_".$budgetDat['TYPE']."_ERROR") );
         //				}
         //			}
         //			else
         //			{
         if (!\CSaleUserAccount::UpdateAccount($userId, $budgetDat['SUM'], $budgetDat['CURRENCY'], $budgetDat['TYPE'], $orderId, '', $paymentId)) {
             $result->addError(new Sale\ResultError(Loc::getMessage("SALE_PROVIDER_USER_BUDGET_" . $budgetDat['TYPE'] . "_ERROR"), "SALE_PROVIDER_USER_BUDGET_" . $budgetDat['TYPE'] . "_ERROR"));
         }
         //			}
         $pool->delete($key);
     }
     return $result;
 }
コード例 #13
0
ファイル: propertyvalue.php プロジェクト: DarneoStudio/bitrix
 function setValueFromPost(array $post)
 {
     $result = new Result();
     $property = $this->property;
     $key = isset($property["ID"]) ? $property["ID"] : "n" . $this->getId();
     $value = isset($post['PROPERTIES'][$key]) ? $post['PROPERTIES'][$key] : null;
     if (isset($post['PROPERTIES'][$key])) {
         $this->setValue($value);
     } else {
         $value = $this->getValue();
     }
     $error = Input\Manager::getError($property, $value);
     if ($property['IS_EMAIL'] == 'Y' && !check_email($value, true)) {
         $error['EMAIL'] = str_replace(array("#EMAIL#", "#NAME#"), array(htmlspecialcharsbx($value), htmlspecialcharsbx($property['NAME'])), Loc::getMessage("SALE_GOPE_WRONG_EMAIL"));
     }
     foreach ($error as $e) {
         $result->addError(new ResultError($property['NAME'] . ' ' . $e, "PROPERTIES[{$key}]"));
     }
     return $result;
 }
コード例 #14
0
 /**
  *
  */
 public function save()
 {
     $result = new Sale\Result();
     $itemsFromDb = array();
     $itemsFromDbList = Internals\BasketPropertyTable::getList(array("filter" => array("BASKET_ID" => $this->getBasketItem()->getId()), "select" => array("ID")));
     while ($itemsFromDbItem = $itemsFromDbList->fetch()) {
         $itemsFromDb[$itemsFromDbItem["ID"]] = true;
     }
     /** @var BasketPropertyItem $basketProperty */
     foreach ($this->collection as $basketProperty) {
         $r = $basketProperty->save();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
         if (isset($itemsFromDb[$basketProperty->getId()])) {
             unset($itemsFromDb[$basketProperty->getId()]);
         }
     }
     foreach ($itemsFromDb as $k => $v) {
         Internals\BasketPropertyTable::delete($k);
     }
     return $result;
 }
コード例 #15
0
ファイル: basket.php プロジェクト: webgksupport/alpina
 /**
  * @return Entity\Result|bool
  * @throws \Bitrix\Main\ArgumentException
  * @throws \Bitrix\Main\ArgumentNullException
  */
 public function save()
 {
     $result = new Result();
     /** @var Order $order */
     $order = $this->getOrder();
     $itemsFromDb = array();
     $filter = array();
     if (!$order) {
         /** @var Main\Entity\Event $event */
         $event = new Main\Event('sale', EventActions::EVENT_ON_BASKET_BEFORE_SAVED, array('ENTITY' => $this));
         $event->send();
         if ($event->getResults()) {
             $result = new Result();
             /** @var Main\EventResult $eventResult */
             foreach ($event->getResults() as $eventResult) {
                 if ($eventResult->getType() == Main\EventResult::ERROR) {
                     $errorMsg = new ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_ON_BEFORE_BASKET_SAVED'), 'SALE_EVENT_ON_BEFORE_BASKET_SAVED');
                     if (isset($eventResultData['ERROR']) && $eventResultData['ERROR'] instanceof ResultError) {
                         $errorMsg = $eventResultData['ERROR'];
                     }
                     $result->addError($errorMsg);
                 }
             }
             if (!$result->isSuccess()) {
                 return $result;
             }
         }
     }
     $isNew = $order && $order->isNew() ? true : false;
     if ($order && !$isNew) {
         $filter['ORDER_ID'] = $order->getId();
     } else {
         if ($this->isLoadForFuserId()) {
             $filter = array('FUSER_ID' => $this->getFUserId(), 'ORDER_ID' => null, 'LID' => $this->getSiteId());
         }
         if ($isNew) {
             $fUserId = $this->getFUserId(true);
             if ($fUserId <= 0) {
                 $userId = $order->getUserId();
                 if (intval($userId) > 0) {
                     $fUserId = Fuser::getIdByUserId($userId);
                     if ($fUserId > 0) {
                         $this->setFUserId($fUserId);
                     }
                 }
             }
         }
     }
     if (!empty($filter)) {
         $itemsFromDbList = Internals\BasketTable::getList(array("filter" => $filter, "select" => array("ID", 'TYPE', 'SET_PARENT_ID', 'PRODUCT_ID', 'NAME', 'QUANTITY')));
         while ($itemsFromDbItem = $itemsFromDbList->fetch()) {
             if (intval($itemsFromDbItem['SET_PARENT_ID']) > 0 && intval($itemsFromDbItem['SET_PARENT_ID']) != $itemsFromDbItem['ID']) {
                 continue;
             }
             $itemsFromDb[$itemsFromDbItem["ID"]] = $itemsFromDbItem;
         }
     }
     /** @var BasketItem $basketItem */
     foreach ($this->collection as $index => $basketItem) {
         $r = $basketItem->save();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
         if (isset($itemsFromDb[$basketItem->getId()]) && $basketItem->getQuantity() > 0) {
             unset($itemsFromDb[$basketItem->getId()]);
         }
     }
     if (!empty($filter)) {
         foreach ($itemsFromDb as $k => $v) {
             if ($v['TYPE'] == static::TYPE_SET) {
                 Internals\BasketTable::deleteBundle($k);
             } else {
                 Internals\BasketTable::deleteWithItems($k);
             }
             /** @var Order $order */
             if ($order && $order->getId() > 0) {
                 OrderHistory::addAction('BASKET', $order->getId(), 'BASKET_REMOVED', $k, null, array('NAME' => $v['NAME'], 'QUANTITY' => $v['QUANTITY'], 'PRODUCT_ID' => $v['PRODUCT_ID']));
             }
         }
     }
     if ($order && $order->getId() > 0) {
         OrderHistory::collectEntityFields('BASKET', $order->getId());
     }
     if (!$order) {
         /** @var Main\Entity\Event $event */
         $event = new Main\Event('sale', EventActions::EVENT_ON_BASKET_SAVED, array('ENTITY' => $this));
         $event->send();
         if ($event->getResults()) {
             $result = new Result();
             /** @var Main\EventResult $eventResult */
             foreach ($event->getResults() as $eventResult) {
                 if ($eventResult->getType() == Main\EventResult::ERROR) {
                     $errorMsg = new ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_ON_BASKET_SAVED'), 'SALE_EVENT_ON_BASKET_SAVED');
                     if (isset($eventResultData['ERROR']) && $eventResultData['ERROR'] instanceof ResultError) {
                         $errorMsg = $eventResultData['ERROR'];
                     }
                     $result->addError($errorMsg);
                 }
             }
             if (!$result->isSuccess()) {
                 return $result;
             }
         }
     }
     return $result;
 }
コード例 #16
0
ファイル: order_ajax.php プロジェクト: webgksupport/alpina
 protected function refreshOrderDataAction()
 {
     $formData = isset($this->request["formData"]) ? $this->request["formData"] : array();
     $additional = isset($this->request["additional"]) ? $this->request["additional"] : array();
     $shipment = null;
     $opResults = new Result();
     //use data from form, don't refresh data from provider
     Admin\OrderEdit::$isTrustProductFormData = true;
     $order = $this->getOrder($formData, $opResults);
     $isStartField = $order->isStartField();
     if ($order->getId() > 0) {
         $order = Admin\OrderEdit::editOrderByFormData($formData, $order, $this->userId, false, array(), $opResults);
     }
     if ($order->getId() <= 0) {
         if (isset($formData['SHIPMENT']) && is_array($formData['SHIPMENT'])) {
             $res = Admin\Blocks\OrderShipment::updateData($order, $formData['SHIPMENT']);
             $res->getErrorMessages();
             $data = $res->getData();
             /** @var \Bitrix\Sale\Shipment $shipment */
             $shipment = array_shift($data['SHIPMENT']);
         }
         if (isset($formData['PAYMENT']) && is_array($formData['PAYMENT'])) {
             $res = Admin\Blocks\OrderPayment::updateData($order, $formData['PAYMENT'], true);
             $res->getErrorMessages();
         }
     }
     if ($isStartField) {
         $hasMeaningfulFields = $order->hasMeaningfulField();
         /** @var Result $r */
         $r = $order->doFinalAction($hasMeaningfulFields);
     }
     $result['PAYABLE'] = $order->getPrice() - $order->getSumPaid();
     $result["BASE_PRICE"] = Admin\Blocks\OrderBasket::getBasePrice($order);
     $data = $this->result->getData();
     if ($shipment) {
         if ($shipment->getField('CUSTOM_PRICE_DELIVERY') == 'Y') {
             $result["CUSTOM_PRICE"] = Admin\Blocks\OrderShipment::getDeliveryPrice($shipment);
         }
         if (!isset($data['SHIPMENT_DATA']['DELIVERY_SERVICE_LIST'])) {
             $deliveryService = Admin\Blocks\OrderShipment::getDeliveryServiceList();
             foreach ($deliveryService as $i => $dlService) {
                 if ($dlService['ID'] <= 0) {
                     continue;
                 }
                 if (!Sale\Delivery\Services\Manager::checkServiceRestriction($dlService['ID'], $shipment, '\\Bitrix\\Sale\\Delivery\\Restrictions\\BySite')) {
                     unset($deliveryService[$i]);
                 }
             }
             $deliveryServiceTree = Admin\Blocks\OrderShipment::makeDeliveryServiceTree($deliveryService);
             $result['DELIVERY_SERVICE_LIST'] = Admin\Blocks\OrderShipment::getTemplate($deliveryServiceTree);
             if (!isset($data['SHIPMENT_DATA']['DELIVERY_ERROR'])) {
                 foreach ($deliveryService as $delivery) {
                     if ($shipment->getDeliveryId() == $delivery['ID'] && $delivery['RESTRICTED']) {
                         $result['DELIVERY_ERROR'] = Loc::getMessage('SALE_OA_ERROR_DELIVERY_SERVICE');
                     }
                 }
             }
         }
         if (!isset($data['SHIPMENT_DATA']['PROFILES'])) {
             if ($shipment->getDeliveryId()) {
                 $service = Sale\Delivery\Services\Manager::getService($shipment->getDeliveryId());
                 $parentService = $service->getParentService();
                 if ($parentService && $parentService->canHasProfiles()) {
                     $profiles = Admin\Blocks\OrderShipment::getDeliveryServiceProfiles($parentService->getId());
                     $profiles = Admin\Blocks\OrderShipment::checkProfilesRestriction($profiles, $shipment);
                     $result["PROFILES"] = Admin\Blocks\OrderShipment::getProfileEditControl($profiles);
                     if (!isset($data['SHIPMENT_DATA']['DELIVERY_ERROR'])) {
                         foreach ($profiles as $profile) {
                             if ($shipment->getDeliveryId() == $profile['ID'] && !$profile['RESTRICTED']) {
                                 $result['DELIVERY_ERROR'] = Loc::getMessage('SALE_OA_ERROR_DELIVERY_SERVICE');
                             }
                         }
                     }
                 }
             }
         }
     }
     $paySystemList = Admin\Blocks\OrderPayment::getPaySystemList($order);
     $result['PAY_SYSTEM_LIST'] = Admin\Blocks\OrderPayment::makePaymentSelectHtmlBody($paySystemList);
     $orderBasket = new Admin\Blocks\OrderBasket($order, "", $this->request["formData"]["BASKET_PREFIX"]);
     $basketPrepareParams = array();
     if (!empty($additional["operation"]) && $additional["operation"] == "PRODUCT_ADD" || $this->request["action"] == "addProductToBasket") {
         $basketPrepareParams["SKIP_SKU_INFO"] = false;
     } else {
         $basketPrepareParams["SKIP_SKU_INFO"] = true;
     }
     $result["BASKET"] = $orderBasket->prepareData($basketPrepareParams);
     // collect info about changed fields
     if ($basketPrepareParams["SKIP_SKU_INFO"] && !empty($formData["PRODUCT"]) && is_array($formData["PRODUCT"])) {
         //prices
         $result["BASKET"]["PRICES_UPDATED"] = array();
         $errors = array();
         $PRECISE = 0.005;
         foreach ($formData["PRODUCT"] as $basketCode => $itemParams) {
             if ($basketCode == "new") {
                 continue;
             }
             if (!isset($result["BASKET"]["ITEMS"][$basketCode]["PRICE"]) || !isset($itemParams["PRICE"])) {
                 $errors[] = "Product price with basket code \"" . $basketCode . "\" not found.";
                 continue;
             }
             if (abs(floatval($result["BASKET"]["ITEMS"][$basketCode]["PRICE"]) - floatval($itemParams["PRICE"])) >= $PRECISE) {
                 $result["BASKET"]["PRICES_UPDATED"][$basketCode] = $result["BASKET"]["ITEMS"][$basketCode]["PRICE"];
             }
         }
         if (!empty($errors)) {
             $this->addResultData("ERROR_PRICE_COMPARING", $errors);
         }
     }
     $resData = $opResults->getData();
     if (!empty($resData["NEW_ITEM_BASKET_CODE"])) {
         $result["BASKET"]["NEW_ITEM_BASKET_CODE"] = $resData["NEW_ITEM_BASKET_CODE"];
     }
     $result['RELATED_PROPS'] = Admin\Blocks\OrderBuyer::getRelPropData($order);
     $result["DISCOUNTS_LIST"] = Admin\OrderEdit::getOrderedDiscounts($order, false);
     if ($order->getBasket()) {
         $result['BASE_PRICE_DELIVERY'] = $result["DISCOUNTS_LIST"]['PRICES']['DELIVERY']['BASE_PRICE'];
     } else {
         $result['BASE_PRICE_DELIVERY'] = $order->getDeliveryPrice();
     }
     $result['BASE_PRICE_DELIVERY'] = roundEx($result['BASE_PRICE_DELIVERY'], SALE_VALUE_PRECISION);
     $result['DELIVERY_PRICE_DISCOUNT'] = roundEx($result["DISCOUNTS_LIST"]['PRICES']['DELIVERY']['PRICE'], SALE_VALUE_PRECISION);
     $result["COUPONS_LIST"] = Admin\OrderEdit::getCouponList($order, false);
     $result["TOTAL_PRICES"] = Admin\OrderEdit::getTotalPrices($order, $orderBasket, false);
     $result["DELIVERY_DISCOUNT"] = $result["TOTAL_PRICES"]["DELIVERY_DISCOUNT"];
     $result = array_merge($result, $order->getFieldValues());
     if (!isset($result["PRICE"])) {
         $result["PRICE"] = 0;
     }
     /* DEMANDED */
     if (isset($additional["demanded"]) && is_array($additional["demanded"])) {
         if (isset($additional["given"]) && is_array($additional["given"])) {
             $result = array_merge($result, $additional["given"]);
         }
         $demanded = $this->getDemandedFields($additional["demanded"], $result, $order);
         $result = array_merge($result, $demanded);
     }
     /* * */
     if (!$opResults->isSuccess()) {
         foreach ($opResults->getErrors() as $error) {
             if ($error->getCode() == "CATALOG_QUANTITY_NOT_ENOGH" || $error->getCode() == "SALE_ORDER_SYSTEM_SHIPMENT_LESS_QUANTITY" || $error->getCode() == "CATALOG_NO_QUANTITY_PRODUCT") {
                 $this->addResultError($error->getMessage());
             }
         }
     }
     $this->addResultData("ORDER_DATA", $result);
 }
コード例 #17
0
ファイル: orderbase.php プロジェクト: Satariall/izurit
 /**
  * @internal
  */
 public function refreshVat()
 {
     $result = new Result();
     if (($basket = $this->getBasket()) && count($basket) > 0) {
         $this->resetVat();
         $basketVatRate = $basket->getVatRate();
         if ($basketVatRate > 0) {
             /** @var Result $r */
             $r = $this->setField('USE_VAT', 'Y');
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
             /** @var Result $r */
             $r = $this->setField('VAT_RATE', $basketVatRate);
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
             /** @var Result $r */
             $r = $this->setField('VAT_SUM', $basket->getVatSum());
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
         }
     }
     return $result;
 }
コード例 #18
0
ファイル: payment.php プロジェクト: DarneoStudio/bitrix
 /**
  * @param $name
  * @param $value
  * @return Result
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\NotImplementedException
  * @throws \Exception
  */
 public function setField($name, $value)
 {
     if ($name == "PAY_SYSTEM_ID") {
         if (intval($value) > 0 && !PaySystemService::isExist($value)) {
             $result = new Result();
             $result->addError(new ResultError(Loc::getMessage('SALE_PAYMENT_WRONG_PAYMENT_SERVICE'), 'SALE_PAYMENT_WRONG_PAYMENT_SERVICE'));
             return $result;
         }
         /** @var PaymentCollection $paymentCollection */
         if (!($paymentCollection = $this->getCollection())) {
             throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found');
         }
         if (count($paymentCollection) == 1) {
             /** @var Order $order */
             if ($order = $paymentCollection->getOrder()) {
                 if (strval($order->getField('PAY_SYSTEM_ID')) == '') {
                     $order->setFieldNoDemand('PAY_SYSTEM_ID', intval($value));
                 }
             }
         }
     }
     return parent::setField($name, $value);
 }
コード例 #19
0
ファイル: shipment.php プロジェクト: andy-profi/bxApiDocs
 /**
  * @internal
  *
  * @param BasketItem $basketItem
  * @param $value
  * @param $oldValue
  *
  * @return Result
  */
 public function syncQuantityAfterModify(BasketItem $basketItem, $value = null, $oldValue = null)
 {
     $result = new Result();
     $shipmentItemCollection = $this->getShipmentItemCollection();
     $shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode());
     if ($shipmentItem === null) {
         if ($value == 0) {
             return new Result();
         }
         $shipmentItem = $shipmentItemCollection->createItem($basketItem);
     }
     $deltaQuantity = $value - $oldValue;
     if ($deltaQuantity > 0) {
         $shipmentItem->setFieldNoDemand("QUANTITY", $shipmentItem->getField("QUANTITY") + $deltaQuantity);
         if ($this->needReservation()) {
             Provider::tryReserveShipmentItem($shipmentItem);
         }
     } else {
         if (floatval($shipmentItem->getField("QUANTITY")) <= 0) {
             return new Result();
         }
         if ($value != 0 && $shipmentItem->getField("QUANTITY") < -$deltaQuantity) {
             $result = new Result();
             $result->addError(new ResultError(str_replace(array("#NAME#", "#QUANTITY#", "#DELTA_QUANTITY#"), array($basketItem->getField("NAME"), $shipmentItem->getField("QUANTITY"), abs($deltaQuantity)), Loc::getMessage('SALE_SHIPMENT_SYSTEM_QUANTITY_ERROR')), 'SALE_SHIPMENT_SYSTEM_QUANTITY_ERROR'));
             return $result;
         }
         if ($value > 0) {
             $shipmentItem->setFieldNoDemand("QUANTITY", $shipmentItem->getField("QUANTITY") + $deltaQuantity);
             if ($this->needReservation()) {
                 Provider::tryReserveShipmentItem($shipmentItem);
             }
         } else {
             $shipmentItem->setFieldNoDemand("QUANTITY", 0);
         }
     }
     return $result;
 }
コード例 #20
0
ファイル: shipmentitem.php プロジェクト: webgksupport/alpina
 /**
  * @return Result
  * @throws Main\NotSupportedException
  */
 protected function calculateDelivery()
 {
     $result = new Result();
     /** @var ShipmentItemCollection $collection */
     $collection = $this->getCollection();
     /** @var Shipment $shipment */
     $shipment = $collection->getShipment();
     /** @var ShipmentCollection $shipmentCollection */
     $shipmentCollection = $shipment->getCollection();
     /** @var Order $order */
     $order = $shipmentCollection->getOrder();
     if ($order->getId() > 0) {
         return $result;
     }
     $deliveryCalculate = $shipment->calculateDelivery();
     if (!$deliveryCalculate->isSuccess()) {
         $result->addErrors($deliveryCalculate->getErrors());
     }
     if ($deliveryCalculate->getPrice() > 0) {
         $shipment->setField('BASE_PRICE_DELIVERY', $deliveryCalculate->getPrice());
     }
     return $result;
 }
コード例 #21
0
ファイル: order.php プロジェクト: akniyev/itprom_dobrohost
 /**
  * @internal
  * @param $id
  *
  * @return Sale\Result
  * @throws Exception
  * @throws \Bitrix\Main\ArgumentNullException
  */
 protected static function setIdAsAccountNumber($id)
 {
     $result = new Sale\Result();
     $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N');
     if ($isOrderConverted == "Y") {
         $accountNumber = $id;
         for ($i = 1; $i <= 10; $i++) {
             try {
                 /** @var \Bitrix\Sale\Result $r */
                 $r = \Bitrix\Sale\Internals\OrderTable::update($id, array("ACCOUNT_NUMBER" => $accountNumber));
                 $res = $r->isSuccess(true);
             } catch (\Bitrix\Main\DB\SqlQueryException $exception) {
                 $res = false;
                 $accountNumber = $id . "-" . $i;
             }
             if ($res) {
                 break;
             }
         }
     } else {
         $res = CSaleOrder::Update($id, array("ACCOUNT_NUMBER" => $id), false);
     }
     if (!$res) {
         $result->addError(new Sale\ResultError(Loc::getMessage('SALE_ORDER_GENERATE_ACCOUNT_NUMBER_ORDER_NUMBER_IS_NOT_SET_AS_ID'), 'SALE_ORDER_GENERATE_ACCOUNT_NUMBER_ORDER_NUMBER_IS_NOT_SET_AS_ID'));
         return $result;
     }
     $result->setData(array('ACCOUNT_NUMBER' => $id));
     return $result;
 }
コード例 #22
0
ファイル: ordershipment.php プロジェクト: Satariall/izurit
 /**
  * @param Order $order
  * @param array $shipments
  * @return Result
  * @throws SystemException
  */
 public static function updateData(Order &$order, array $shipments)
 {
     global $USER;
     $result = new Result();
     $data = array();
     $basketResult = null;
     if (!$order) {
         $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_ORDER_NOT_FOUND')));
         return $result;
     }
     $shipmentCollection = $order->getShipmentCollection();
     $isStartField = $shipmentCollection->isStartField();
     foreach ($shipments as $item) {
         $shipmentId = intval($item['SHIPMENT_ID']);
         $isNew = $shipmentId <= 0;
         if ($isNew) {
             self::$shipment = $shipmentCollection->createItem();
         } else {
             self::$shipment = $shipmentCollection->getItemById($shipmentId);
             if (!self::$shipment) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_SHIPMENT_NOT_FOUND')));
                 continue;
             }
         }
         self::$defaultFields = self::$shipment->getFieldValues();
         /** @var \Bitrix\Sale\BasketItem $product */
         $countItems = count(self::$shipment->getShipmentItemCollection());
         $systemShipment = $shipmentCollection->getSystemShipment();
         $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
         $products = array();
         if (!isset($item['PRODUCT']) && self::$shipment->getId() <= 0) {
             $basket = $order->getBasket();
             if ($basket) {
                 $basketItems = $basket->getBasketItems();
                 foreach ($basketItems as $product) {
                     $systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($product->getBasketCode());
                     if ($product->isBundleChild() || !$systemShipmentItem || $systemShipmentItem->getQuantity() <= 0) {
                         continue;
                     }
                     $products[] = array('AMOUNT' => $product->getQuantity(), 'BASKET_CODE' => $product->getBasketCode());
                 }
             }
         } else {
             $products = $item['PRODUCT'];
         }
         if ($item['DEDUCTED'] == 'Y') {
             $basketResult = OrderBasketShipment::updateData($order, self::$shipment, $products);
             if (!$basketResult->isSuccess()) {
                 $result->addErrors($basketResult->getErrors());
             }
         }
         $extraServices = $item['EXTRA_SERVICES'] ? $item['EXTRA_SERVICES'] : array();
         $shipmentFields = array('COMPANY_ID' => isset($item['COMPANY_ID']) && $item['COMPANY_ID'] > 0 ? $item['COMPANY_ID'] : 0, 'DEDUCTED' => $item['DEDUCTED'], 'DELIVERY_DOC_NUM' => $item['DELIVERY_DOC_NUM'], 'TRACKING_NUMBER' => $item['TRACKING_NUMBER'], 'CURRENCY' => $order->getCurrency(), 'COMMENTS' => $item['COMMENTS'], 'STATUS_ID' => $isNew ? DeliveryStatus::getInitialStatus() : $item['STATUS_ID']);
         if ($item['DELIVERY_DOC_DATE']) {
             try {
                 $shipmentFields['DELIVERY_DOC_DATE'] = new Date($item['DELIVERY_DOC_DATE']);
             } catch (Main\ObjectException $exception) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_UNCORRECT_FORM_DATE')));
             }
         }
         $shipmentFields['DELIVERY_ID'] = $item['PROFILE'] > 0 ? $item['PROFILE'] : $item['DELIVERY_ID'];
         try {
             $service = Services\Manager::getService($shipmentFields['DELIVERY_ID']);
             if ($service->getParentService()) {
                 $shipmentFields['DELIVERY_NAME'] = $service->getParentService()->getName() . ':' . $service->getName();
             } else {
                 $shipmentFields['DELIVERY_NAME'] = $service->getName();
             }
         } catch (Main\ArgumentNullException $e) {
             $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_NO_DELIVERY_SERVICE')));
         }
         $responsibleId = self::$shipment->getField('RESPONSIBLE_ID');
         if ($item['RESPONSIBLE_ID'] != $responsibleId || empty($responsibleId)) {
             if (isset($item['RESPONSIBLE_ID'])) {
                 $shipmentFields['RESPONSIBLE_ID'] = $item['RESPONSIBLE_ID'];
             } else {
                 $shipmentFields['RESPONSIBLE_ID'] = $order->getField('RESPONSIBLE_ID');
             }
             if (!empty($shipmentFields['RESPONSIBLE_ID'])) {
                 $shipmentFields['EMP_RESPONSIBLE_ID'] = $USER->getID();
                 $shipmentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
             }
         }
         if ($extraServices) {
             self::$shipment->setExtraServices($extraServices);
         }
         $setFieldsResult = self::$shipment->setFields($shipmentFields);
         if (!$setFieldsResult->isSuccess()) {
             $result->addErrors($setFieldsResult->getErrors());
         }
         self::$shipment->setStoreId($item['DELIVERY_STORE_ID']);
         if ($item['DEDUCTED'] == 'N') {
             $basketResult = OrderBasketShipment::updateData($order, self::$shipment, $products);
             if (!$basketResult->isSuccess()) {
                 $result->addErrors($basketResult->getErrors());
             }
         }
         try {
             $priceDeliveryInfo = array();
             if ($item['CUSTOM_PRICE_DELIVERY'] != 'Y') {
                 $totalPrice = self::getDeliveryPrice(self::$shipment);
             } else {
                 $totalPrice = (double) str_replace(',', '.', $item['BASE_PRICE_DELIVERY']);
             }
         } catch (\Exception $e) {
             $totalPrice = 0;
         }
         $priceDeliveryInfo['CUSTOM_PRICE_DELIVERY'] = $item['CUSTOM_PRICE_DELIVERY'];
         $priceDeliveryInfo['BASE_PRICE_DELIVERY'] = $totalPrice;
         self::$shipment->setFields($priceDeliveryInfo);
         self::$shipment->setField('ALLOW_DELIVERY', $item['ALLOW_DELIVERY']);
         $data['SHIPMENT'][] = self::$shipment;
     }
     if ($isStartField) {
         $hasMeaningfulFields = $shipmentCollection->hasMeaningfulField();
         /** @var Result $r */
         $r = $shipmentCollection->doFinalAction($hasMeaningfulFields);
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     }
     $result->setData($data);
     return $result;
 }
コード例 #23
0
ファイル: order.php プロジェクト: webgksupport/alpina
 /**
  * @param bool $hasMeaningfulField
  * @return Result
  * @throws Main\ArgumentNullException
  * @throws Main\ObjectNotFoundException
  */
 public function doFinalAction($hasMeaningfulField = false)
 {
     $result = new Result();
     if (!$hasMeaningfulField) {
         $this->clearStartField();
         return $result;
     }
     if ($basket = $this->getBasket()) {
         $this->setMathActionOnly(true);
         if ($eventName = static::getEntityEventName()) {
             $event = new Main\Event('sale', 'OnBefore' . $eventName . 'FinalAction', array('ENTITY' => $this, 'HAS_MEANINGFUL_FIELD' => $hasMeaningfulField, 'BASKET' => $basket));
             $event->send();
             if ($event->getResults()) {
                 /** @var Main\EventResult $eventResult */
                 foreach ($event->getResults() as $eventResult) {
                     if ($eventResult->getType() == Main\EventResult::ERROR) {
                         $errorMsg = new ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_ON_BEFORE_' . strtoupper($eventName) . '_FINAL_ACTION_ERROR'), 'SALE_EVENT_ON_BEFORE_' . strtoupper($eventName) . '_FINAL_ACTION_ERROR');
                         if ($eventResultData = $eventResult->getParameters()) {
                             if (isset($eventResultData['ERROR']) && $eventResultData['ERROR'] instanceof ResultError) {
                                 $errorMsg = $eventResultData['ERROR'];
                             }
                         }
                         $result->addError($errorMsg);
                     }
                 }
             }
             if (!$result->isSuccess()) {
                 return $result;
             }
         }
         // discount
         $discount = $this->getDiscount();
         $r = $discount->calculate();
         if (!$r->isSuccess()) {
             //				$this->clearStartField();
             //				$result->addErrors($r->getErrors());
             //				return $result;
         }
         if ($r->isSuccess() && ($discountData = $r->getData()) && !empty($discountData) && is_array($discountData)) {
             /** @var Result $r */
             $r = $this->applyDiscount($discountData);
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
                 return $result;
             }
         }
         if (!$this->isExternal()) {
             /** @var Tax $tax */
             $tax = $this->getTax();
             /** @var Result $r */
             $r = $tax->calculate();
             if (!$result->isSuccess()) {
                 return $r;
             }
             $r = $tax->calculateDelivery();
             if (!$result->isSuccess()) {
                 return $r;
             }
             $taxChanged = false;
             $taxResult = $r->getData();
             if (isset($taxResult['TAX_PRICE']) && floatval($taxResult['TAX_PRICE']) >= 0) {
                 if (!$this->isUsedVat()) {
                     $taxChanged = true;
                     $this->setField('TAX_PRICE', $taxResult['TAX_PRICE']);
                     $this->setFieldNoDemand("PRICE", $this->getBasket()->getPrice() + $this->getShipmentCollection()->getPriceDelivery() + $taxResult['TAX_PRICE']);
                 }
             }
             if ($taxChanged || $this->isUsedVat()) {
                 $taxValue = $this->isUsedVat() ? $this->getVatSum() : $this->getField('TAX_PRICE');
                 if (floatval($taxValue) != floatval($this->getField('TAX_VALUE'))) {
                     $this->setField('TAX_VALUE', floatval($taxValue));
                 }
             }
         }
     }
     //
     $this->setMathActionOnly(false);
     //
     /** @var Result $r */
     $r = $this->syncOrderAndPayments();
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
     }
     $this->clearStartField();
     if ($eventName = static::getEntityEventName()) {
         $event = new Main\Event('sale', 'OnAfter' . $eventName . 'FinalAction', array('ENTITY' => $this));
         $event->send();
     }
     return $result;
 }
コード例 #24
0
 /**
  * @param $name
  * @param $oldValue
  * @param $value
  * @return Result
  */
 public function onOrderModify($name, $oldValue, $value)
 {
     $result = new Result();
     switch ($name) {
         case "CANCELED":
             if ($value == "Y") {
                 $isPaid = false;
                 /** @var Payment $payment */
                 foreach ($this->collection as $payment) {
                     if ($payment->isPaid()) {
                         $isPaid = true;
                         break;
                     }
                 }
                 if ($isPaid) {
                     $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_CANCEL_PAYMENT_EXIST_ACTIVE'), 'SALE_ORDER_CANCEL_PAYMENT_EXIST_ACTIVE'));
                 }
             }
             break;
     }
     return $result;
 }
コード例 #25
0
ファイル: orderpayment.php プロジェクト: DarneoStudio/bitrix
 /**
  * @param Order $order
  * @param $payments
  * @param bool $canSetPaid
  * @return Result
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\ObjectNotFoundException
  * @throws UserMessageException
  */
 public static function updateData(Order &$order, $payments, $canSetPaid = false)
 {
     global $USER;
     $result = new Result();
     $data['PAYMENT'] = array();
     if (!$order) {
         throw new UserMessageException('Order does not exist');
     }
     foreach ($payments as $payment) {
         $paymentId = intval($payment['PAYMENT_ID']);
         $isNew = $paymentId <= 0;
         $paymentCollection = $order->getPaymentCollection();
         /** @var \Bitrix\Sale\Payment $paymentItem */
         if ($isNew) {
             $paymentItem = $paymentCollection->createItem();
         } else {
             $paymentItem = $paymentCollection->getItemById($paymentId);
             if (!$paymentItem) {
                 throw new UserMessageException('Payment does not exist');
             }
         }
         self::$defaultFields = $paymentItem->getFieldValues();
         $isReturn = isset($payment['IS_RETURN']) && $payment['IS_RETURN'] == 'Y';
         /** @var \Bitrix\Sale\PaySystemService $paymentService */
         $paymentService = PaySystemService::load($payment['PAY_SYSTEM_ID']);
         if (!$paymentService) {
             $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_ERROR_PAYSYSTEM')));
         }
         $paymentFields = array('PAY_SYSTEM_ID' => $payment['PAY_SYSTEM_ID'], 'COMPANY_ID' => isset($payment['COMPANY_ID']) ? $payment['COMPANY_ID'] : 0, 'SUM' => $payment['SUM'], 'PAY_VOUCHER_NUM' => $payment['PAY_VOUCHER_NUM'], 'PAY_RETURN_NUM' => $payment['PAY_RETURN_NUM'], 'PAY_RETURN_COMMENT' => $payment['PAY_RETURN_COMMENT'], 'COMMENTS' => $payment['COMMENTS'], 'PAY_SYSTEM_NAME' => $paymentService ? $paymentService->getName() : '');
         if ($isNew) {
             $paymentFields['DATE_BILL'] = new DateTime();
         }
         if (!empty($payment['PAY_RETURN_DATE'])) {
             try {
                 $paymentFields['PAY_RETURN_DATE'] = new Date($payment['PAY_RETURN_DATE']);
             } catch (Main\ObjectException $exception) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_ERROR_RETURN_DATE_FORMAT')));
             }
         }
         if (!empty($payment['PAY_VOUCHER_DATE'])) {
             try {
                 $paymentFields['PAY_VOUCHER_DATE'] = new Date($payment['PAY_VOUCHER_DATE']);
             } catch (Main\ObjectException $exception) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_ERROR_VOUCHER_DATE_FORMAT')));
             }
         }
         if (isset($payment['RESPONSIBLE_ID'])) {
             $paymentFields['RESPONSIBLE_ID'] = !empty($payment['RESPONSIBLE_ID']) ? $payment['RESPONSIBLE_ID'] : $USER->GetID();
             if ($payment['RESPONSIBLE_ID'] != $paymentItem->getField('RESPONSIBLE_ID')) {
                 $paymentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
                 if (!$isNew) {
                     $paymentFields['EMP_RESPONSIBLE_ID'] = $USER->GetID();
                 }
             }
         }
         if ($result->isSuccess()) {
             if ($paymentItem->getField('PAID') != $payment['PAID'] && $paymentItem->getField('IS_RETURN') == 'Y') {
                 $setResult = $paymentItem->setReturn('N');
                 if (!$setResult->isSuccess()) {
                     $result->addErrors($setResult->getErrors());
                 }
             }
             if ($isReturn && $payment['OPERATION_ID'] == 'RETURN') {
                 $setResult = $paymentItem->setReturn('Y');
                 if (!$setResult->isSuccess()) {
                     $result->addErrors($setResult->getErrors());
                 }
             }
             $setResult = $paymentItem->setFields($paymentFields);
             if (!$setResult->isSuccess()) {
                 $result->addErrors($setResult->getErrors());
             }
             if (!$canSetPaid) {
                 $setResult = $paymentItem->setPaid($payment['PAID']);
                 if (!$setResult->isSuccess()) {
                     $result->addErrors($setResult->getErrors());
                 }
             }
             if ($payment['ORDER_STATUS_ID']) {
                 $order->setField('STATUS_ID', $payment['ORDER_STATUS_ID']);
             }
         }
         $data['PAYMENT'][] = $paymentItem;
     }
     $result->setData($data);
     return $result;
 }
コード例 #26
0
ファイル: manager.php プロジェクト: Satariall/izurit
 public static function saveStores($deliveryId, array $storesList)
 {
     $result = new Result();
     $storesFields = self::getStoresFields($deliveryId);
     if (!empty($storesFields)) {
         $res = Table::update($storesFields["ID"], array("PARAMS" => array("STORES" => $storesList)));
     } else {
         $res = Table::add(array("CODE" => self::STORE_PICKUP_CODE, "NAME" => Loc::getMessage("DELIVERY_SERVICE_MANAGER_ES_NAME"), "DESCRIPTION" => Loc::getMessage("DELIVERY_SERVICE_MANAGER_ES_DESCRIPTION"), "CLASS_NAME" => self::STORE_PICKUP_CLASS, "DELIVERY_ID" => $deliveryId, "RIGHTS" => "YYY", "PARAMS" => array("STORES" => $storesList)));
     }
     if (!$res->isSuccess()) {
         foreach ($res->getErrors() as $error) {
             $result->addError($error);
         }
     }
     return $result;
 }
コード例 #27
0
 /**
  * @return Result
  * @throws Main\ObjectNotFoundException
  */
 public function delete()
 {
     $result = new Result();
     /** @var Result $r */
     $r = $this->setField("QUANTITY", 0);
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
         return $result;
     }
     return parent::delete();
 }
コード例 #28
0
 /**
  * @return Main\Entity\AddResult|Main\Entity\UpdateResult
  * @throws Main\ArgumentNullException
  * @throws Main\ArgumentOutOfRangeException
  * @throws \Exception
  */
 public function save()
 {
     global $USER;
     $result = new Result();
     $id = $this->getId();
     $fields = $this->fields->getValues();
     /** @var ShipmentItemStoreCollection $collection */
     $collection = $this->getCollection();
     /** @var Result $r */
     $r = $collection->checkAvailableQuantity($this);
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
         return $result;
     }
     /** @var BasketItem $basketItem */
     $basketItem = $this->getBasketItem();
     if ($id > 0) {
         $fields = $this->fields->getChangedValues();
         if (!empty($fields) && is_array($fields)) {
             if (isset($fields["QUANTITY"]) && floatval($fields["QUANTITY"]) <= 0) {
                 throw new Main\ArgumentNullException('quantity');
             }
             $fields['DATE_MODIFY'] = new Main\Type\DateTime();
             $fields['MODIFIED_BY'] = $USER->GetID();
             $r = Internals\ShipmentItemStoreTable::update($id, $fields);
             if (!$r->isSuccess()) {
                 return $r;
             }
         }
         $result = new Main\Entity\UpdateResult();
     } else {
         if (!isset($fields["ORDER_DELIVERY_BASKET_ID"])) {
             $fields['ORDER_DELIVERY_BASKET_ID'] = $this->getParentShipmentItemId();
         }
         if (!isset($fields["BASKET_ID"])) {
             $fields['BASKET_ID'] = $basketItem->getId();
         }
         $fields['DATE_CREATE'] = new Main\Type\DateTime();
         if (!isset($fields["QUANTITY"]) || floatval($fields["QUANTITY"]) == 0) {
             return new Main\Entity\AddResult();
         }
         if ($basketItem->isBarcodeMulti() && isset($fields['BARCODE']) && strval(trim($fields['BARCODE'])) == "") {
             $result->addError(new ResultError(Loc::getMessage('SHIPMENT_ITEM_STORE_BARCODE_MULTI_EMPTY', array('#PRODUCT_NAME#' => $basketItem->getField('NAME'), '#STORE_ID#' => $fields['STORE_ID'])), 'SHIPMENT_ITEM_STORE_BARCODE_MULTI_EMPTY'));
             return $result;
         }
         $r = Internals\ShipmentItemStoreTable::add($fields);
         if (!$r->isSuccess()) {
             return $r;
         }
         $id = $r->getId();
         $this->setFieldNoDemand('ID', $id);
         $result = new Main\Entity\AddResult();
     }
     return $result;
 }
コード例 #29
0
ファイル: entity.php プロジェクト: webgksupport/alpina
 /**
  *
  * @param array $values
  * @return Result
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\NotSupportedException
  * @throws \Exception
  */
 public function setFields(array $values)
 {
     $resultData = array();
     $result = new Result();
     $oldValues = null;
     foreach ($values as $key => $value) {
         $oldValues[$key] = $this->fields->get($key);
     }
     if ($eventName = static::getEntityEventName()) {
         $event = new Main\Event('sale', 'OnBefore' . $eventName . 'SetFields', array('ENTITY' => $this, 'VALUES' => $values, 'OLD_VALUES' => $oldValues));
         $event->send();
         if ($event->getResults()) {
             /** @var Main\EventResult $eventResult */
             foreach ($event->getResults() as $eventResult) {
                 if ($eventResult->getType() == Main\EventResult::SUCCESS) {
                     if ($eventResultData = $eventResult->getParameters()) {
                         if (isset($eventResultData['VALUES'])) {
                             $values = $eventResultData['VALUES'];
                         }
                     }
                 } elseif ($eventResult->getType() == Main\EventResult::ERROR) {
                     $errorMsg = new ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_ON_BEFORE_' . strtoupper($eventName) . '_SET_FIELDS_ERROR'), 'SALE_EVENT_ON_BEFORE_' . strtoupper($eventName) . '_SET_FIELDS_ERROR');
                     if ($eventResultData = $eventResult->getParameters()) {
                         if (isset($eventResultData['ERROR']) && $eventResultData['ERROR'] instanceof ResultError) {
                             $errorMsg = $eventResultData['ERROR'];
                         }
                     }
                     $result->addError($errorMsg);
                 }
             }
         }
     }
     if (!$result->isSuccess()) {
         return $result;
     }
     $isStartField = $this->isStartField();
     foreach ($values as $key => $value) {
         $r = $this->setField($key, $value);
         if (!$r->isSuccess()) {
             $data = $r->getData();
             if (!empty($data) && is_array($data)) {
                 $resultData = array_merge($resultData, $data);
             }
             $result->addErrors($r->getErrors());
         }
     }
     if (!empty($resultData)) {
         $result->setData($resultData);
     }
     if ($isStartField) {
         $hasMeaningfulFields = $this->hasMeaningfulField();
         /** @var Result $r */
         $r = $this->doFinalAction($hasMeaningfulFields);
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         } else {
             if (($data = $r->getData()) && !empty($data) && is_array($data)) {
                 $result->setData($result->getData() + $data);
             }
         }
     }
     return $result;
 }
コード例 #30
0
 /**
  * @param BasketItem $basketItem
  *
  * @return Result
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\ObjectNotFoundException
  * @throws \ErrorException
  */
 public function deleteByBasketItem(BasketItem $basketItem)
 {
     $result = new Result();
     $systemShipmentItem = null;
     /** @var Shipment $shipment */
     if (!($shipment = $this->getShipment())) {
         throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
     }
     /** @var ShipmentItem $shipmentItem */
     foreach ($this->collection as $shipmentItem) {
         if ($shipmentItem->getBasketCode() == $basketItem->getBasketCode()) {
             if ($shipment->isSystem()) {
                 $systemShipmentItem = $shipmentItem;
                 continue;
             }
             $r = $shipmentItem->delete();
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
         }
     }
     if ($systemShipmentItem !== null) {
         if ($systemShipmentItem->getReservedQuantity() > 0) {
             /** @var Result $r */
             $r = $systemShipmentItem->tryUnreserve();
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
         }
         if ($result->isSuccess()) {
             $shipmentItem->setFieldNoDemand('QUANTITY', 0);
         }
     }
     return $result;
 }