コード例 #1
0
 /**
  * @return Entity\Result
  */
 public function save()
 {
     $result = new Entity\Result();
     $itemsFromDb = array();
     if ($this->getOrder()->getId() > 0) {
         $itemsFromDbList = Internals\OrderPropsValueTable::getList(array("filter" => array("ORDER_ID" => $this->getOrder()->getId()), "select" => array("ID")));
         while ($itemsFromDbItem = $itemsFromDbList->fetch()) {
             $itemsFromDb[$itemsFromDbItem["ID"]] = true;
         }
     }
     /** @var PropertyValue $property */
     foreach ($this->collection as $property) {
         $r = $property->save();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
         if (isset($itemsFromDb[$property->getId()])) {
             unset($itemsFromDb[$property->getId()]);
         }
     }
     foreach ($itemsFromDb as $k => $v) {
         Internals\OrderPropsValueTable::delete($k);
     }
     return $result;
 }
コード例 #2
0
 /**
  * @return Entity\Result
  * @throws Main\ArgumentException
  * @throws Main\ObjectNotFoundException
  * @throws \Exception
  */
 public function save()
 {
     $result = new Entity\Result();
     $itemsFromDb = array();
     if ($this->getOrder()->getId() > 0) {
         $itemsFromDbList = Internals\PaymentTable::getList(array("filter" => array("ORDER_ID" => $this->getOrder()->getId()), "select" => array("ID")));
         while ($itemsFromDbItem = $itemsFromDbList->fetch()) {
             $itemsFromDb[$itemsFromDbItem["ID"]] = true;
         }
     }
     /** @var Payment $payment */
     foreach ($this->collection as $payment) {
         if ($payment->isInner() && $payment->getSum() == 0 && $payment->getId() == 0) {
             $payment->delete();
         }
     }
     /** @var Payment $payment */
     foreach ($this->collection as $payment) {
         $r = $payment->save();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
         if (isset($itemsFromDb[$payment->getId()])) {
             unset($itemsFromDb[$payment->getId()]);
         }
     }
     foreach ($itemsFromDb as $k => $v) {
         Internals\PaymentTable::delete($k);
         /** @var Order $order */
         if (!($order = $this->getOrder())) {
             throw new Main\ObjectNotFoundException('Entity "Order" not found');
         }
         if ($order->getId() > 0) {
             OrderHistory::addAction('PAYMENT', $order->getId(), 'PAYMENT_REMOVE', $k);
         }
     }
     return $result;
 }
コード例 #3
0
 /**
  * @return Main\Entity\Result
  */
 public function save()
 {
     $result = new Main\Entity\Result();
     $oldBarcodeList = array();
     $itemsFromDb = array();
     if ($this->getShipmentItem() && $this->getShipmentItem()->getId() > 0) {
         $itemsFromDbList = Internals\ShipmentItemStoreTable::getList(array("filter" => array("ORDER_DELIVERY_BASKET_ID" => $this->getShipmentItem()->getId()), "select" => array("*")));
         while ($itemsFromDbItem = $itemsFromDbList->fetch()) {
             $itemsFromDb[$itemsFromDbItem["ID"]] = true;
         }
     }
     /** @var ShipmentItemStore $shipmentItemStore */
     foreach ($this->collection as $shipmentItemStore) {
         $r = $shipmentItemStore->save();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
         if (isset($itemsFromDb[$shipmentItemStore->getId()])) {
             unset($itemsFromDb[$shipmentItemStore->getId()]);
         }
     }
     foreach ($itemsFromDb as $k => $v) {
         Internals\ShipmentItemStoreTable::delete($k);
     }
     return $result;
 }
コード例 #4
0
 /**
  * @return Entity\Result
  * @throws Main\ArgumentException
  * @throws Main\ArgumentNullException
  * @throws Main\ObjectNotFoundException
  */
 public function save()
 {
     $result = new Entity\Result();
     $itemsFromDb = array();
     if ($this->getOrder()->getId() > 0) {
         $itemsFromDbList = Internals\ShipmentTable::getList(array("filter" => array("ORDER_ID" => $this->getOrder()->getId()), "select" => array("ID", "DELIVERY_NAME")));
         while ($itemsFromDbItem = $itemsFromDbList->fetch()) {
             $itemsFromDb[$itemsFromDbItem["ID"]] = $itemsFromDbItem;
         }
     }
     /** @var Shipment $shipment */
     foreach ($this->collection as $shipment) {
         if ($shipment->isSystem()) {
             continue;
         }
         if (($systemShipment = $this->getSystemShipment()) && $systemShipment->getId() == 0) {
             /** @var Result $r */
             $r = $this->cloneShipment($shipment, $systemShipment);
             if ($r->isSuccess()) {
                 break;
             } else {
                 $result->addErrors($r->getErrors());
             }
         }
     }
     /** @var Shipment $shipment */
     foreach ($this->collection as $shipment) {
         $r = $shipment->save();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
         if (isset($itemsFromDb[$shipment->getId()])) {
             unset($itemsFromDb[$shipment->getId()]);
         }
     }
     foreach ($itemsFromDb as $k => $v) {
         Internals\ShipmentTable::deleteWithItems($k);
         /** @var Order $order */
         if (!($order = $this->getOrder())) {
             throw new Main\ObjectNotFoundException('Entity "Order" not found');
         }
         if ($order->getId() > 0) {
             OrderHistory::addAction('SHIPMENT', $order->getId(), 'SHIPMENT_REMOVED', $k, null, array('ID' => $k, 'DELIVERY_NAME' => $v['DELIVERY_NAME']));
         }
     }
     if ($this->getOrder()->getId() > 0) {
         OrderHistory::collectEntityFields('SHIPMENT', $this->getOrder()->getId());
     }
     return $result;
 }
コード例 #5
0
 /**
  * @return Main\Entity\Result
  * @throws Main\ArgumentException
  * @throws Main\ArgumentNullException
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\ObjectNotFoundException
  */
 public function save()
 {
     $result = new Main\Entity\Result();
     $itemsFromDb = array();
     if ($this->getShipment()->getId() > 0) {
         $itemsFromDbList = Internals\ShipmentItemTable::getList(array("filter" => array("ORDER_DELIVERY_ID" => $this->getShipment()->getId()), "select" => array("ID", 'BASKET_ID')));
         while ($itemsFromDbItem = $itemsFromDbList->fetch()) {
             $itemsFromDb[$itemsFromDbItem["ID"]] = $itemsFromDbItem;
         }
     }
     /** @var ShipmentItem $shipmentItem */
     foreach ($this->collection as $shipmentItem) {
         /** @var BasketItem $basketItem */
         if (!($basketItem = $shipmentItem->getBasketItem())) {
             throw new Main\ObjectNotFoundException('Entity "BasketItem" not found');
         }
         if ($basketItem->isBundleParent()) {
             $this->addBundleToCollection($basketItem);
         }
     }
     /** @var Shipment $shipment */
     if (!($shipment = $this->getShipment())) {
         throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
     }
     /** @var ShipmentItem $shipmentItem */
     foreach ($this->collection as $shipmentItem) {
         if ($shipment->isSystem() && $shipmentItem->getQuantity() == 0) {
             continue;
         }
         $r = $shipmentItem->save();
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
         if (isset($itemsFromDb[$shipmentItem->getId()])) {
             unset($itemsFromDb[$shipmentItem->getId()]);
         }
     }
     /** @var ShipmentCollection $shipmentCollection */
     if (!($shipmentCollection = $shipment->getCollection())) {
         throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
     }
     /** @var Order $order */
     if (!($order = $shipmentCollection->getOrder())) {
         throw new Main\ObjectNotFoundException('Entity "Order" not found');
     }
     /** @var Basket $basket */
     if (!($basket = $order->getBasket())) {
         throw new Main\ObjectNotFoundException('Entity "Basket" not found');
     }
     foreach ($itemsFromDb as $k => $v) {
         Internals\ShipmentItemTable::deleteWithItems($k);
         /** @var BasketItem $basketItem */
         if ($basketItem = $basket->getItemById($k)) {
             OrderHistory::addAction('SHIPMENT', $order->getId(), 'SHIPMENT_ITEM_BASKET_REMOVED', $shipment->getId(), null, array('NAME' => $basketItem->getField('NAME'), 'QUANTITY' => $basketItem->getQuantity(), 'PRODUCT_ID' => $basketItem->getProductId()));
         }
     }
     return $result;
 }
コード例 #6
0
ファイル: orderedit.php プロジェクト: DarneoStudio/bitrix
 /**
  * @param array $formData
  * @param $creatorUserId
  * @param bool $createUserIfNeed
  * @param array $files
  * @param Result &$opResult
  * @return Order|static
  * @throws ArgumentNullException
  * @throws SystemException
  */
 public static function createOrderFromForm(array $formData, $creatorUserId, $createUserIfNeed = true, array $files = array(), Result &$opResult)
 {
     if (!isset($formData["SITE_ID"]) || strlen($formData["SITE_ID"]) <= 0) {
         throw new ArgumentNullException('formData["SITE_ID"]');
     }
     $order = Order::create($formData["SITE_ID"]);
     $order = self::fillSimpleFields($order, $formData, $creatorUserId);
     $propCollection = $order->getPropertyCollection();
     $res = $propCollection->setValuesFromPost($formData, $files);
     $opResult->addErrors($res->getErrors());
     //creates new user if need
     $order->setFieldNoDemand("USER_ID", self::getUserId($order, $formData, $createUserIfNeed, $opResult));
     $fUserId = null;
     if ($order->getUserId() > 0) {
         $fUserId = Fuser::getIdByUserId($order->getUserId());
     }
     //init basket
     if (isset($formData["PRODUCT"]) && is_array($formData["PRODUCT"])) {
         $basket = \Bitrix\Sale\Basket::create($formData["SITE_ID"], $fUserId);
         sortByColumn($formData["PRODUCT"], array("BASE_PRICE" => SORT_DESC, "PRICE" => SORT_DESC));
         foreach ($formData["PRODUCT"] as $basketCode => $productData) {
             if ($productData["IS_SET_ITEM"] == "Y") {
                 continue;
             }
             if (!isset($productData["PROPS"]) || !is_array($productData["PROPS"])) {
                 $productData["PROPS"] = array();
             }
             $item = $basket->getExistsItem($productData["MODULE"], $productData["OFFER_ID"], $productData["PROPS"]);
             if ($item == null && $basketCode != "new") {
                 $item = $basket->getItemByBasketCode($basketCode);
             }
             if ($item && $item->isBundleChild()) {
                 $item = null;
             }
             if ($item) {
                 //Let's extract cached provider product data from field
                 if (!empty($productData["PROVIDER_DATA"])) {
                     $providerData = unserialize($productData["PROVIDER_DATA"]);
                     if (is_array($providerData) && !empty($providerData)) {
                         self::setProviderTrustData($item, $order, $providerData);
                     }
                 }
                 if (!empty($productData["SET_ITEMS_DATA"])) {
                     $productData["SET_ITEMS"] = unserialize($productData["SET_ITEMS_DATA"]);
                 }
                 $res = $item->setField("QUANTITY", $item->getField("QUANTITY") + $productData["QUANTITY"]);
                 if (!$res->isSuccess()) {
                     $opResult->addErrors($res->getErrors());
                 }
             } else {
                 $setBasketCode = $basketCode != "new" ? $basketCode : null;
                 $item = $basket->createItem($productData["MODULE"], $productData["OFFER_ID"], $setBasketCode);
                 if ($basketCode != $productData["BASKET_CODE"]) {
                     $productData["BASKET_CODE"] = $item->getBasketCode();
                 }
                 $needDataUpdate = false;
                 if ($basketCode == "new") {
                     $opResult->setData(array("NEW_ITEM_BASKET_CODE" => $productData["BASKET_CODE"]));
                     $needDataUpdate = true;
                 }
                 $fbRes = self::fillBasketItem($item, $productData, $order, $basket, $needDataUpdate);
                 if (!$fbRes->isSuccess()) {
                     $opResult->addErrors($fbRes->getErrors());
                 }
                 if (isset($productData["PROPS"]) && !empty($productData["PROPS"]) && is_array($productData["PROPS"])) {
                     /** @var \Bitrix\Sale\BasketPropertiesCollection $property */
                     $property = $item->getPropertyCollection();
                     $property->setProperty($productData["PROPS"]);
                 }
             }
         }
         $res = $order->setBasket($basket);
         if (!$res->isSuccess()) {
             $opResult->addErrors($res->getErrors());
         }
         if (isset($formData["DISCOUNTS"]) && is_array($formData["DISCOUNTS"])) {
             $order->getDiscount()->setApplyResult($formData["DISCOUNTS"]);
         }
     } else {
         $opResult->addError(new EntityError(Loc::getMessage("SALE_ORDEREDIT_ERROR_NO_PRODUCTS")));
     }
     return $order;
 }