public function order_edit()
 {
     $object = $this->expectObject("param0", true);
     $mode = (string) getRequest('param1');
     $objectId = $object->getId();
     $this->setHeaderLabel("header-users-edit-" . $this->getObjectTypeMethod($object));
     $this->checkSv($objectId);
     $inputData = array("object" => $object, "allowed-element-types" => array('emarket', 'order'));
     if ($mode == "do") {
         $oldDeliveryPrice = $object->getValue('delivery_price');
         $object = $this->saveEditedObjectData($inputData);
         $newDeliveryPrice = $object->getValue('delivery_price');
         $order = order::get($object->id);
         $amounts = getRequest('order-amount-item');
         $dels = getRequest('order-del-item');
         $isChanged = false;
         if (is_array($amounts)) {
             foreach ($amounts as $itemId => $amount) {
                 $item = $order->getItem($itemId);
                 if ($item instanceof orderItem) {
                     if ($item->getAmount() != $amount) {
                         $item->setAmount($amount);
                         $item->commit();
                         $isChanged = true;
                     }
                 }
             }
         }
         if (is_array($dels)) {
             foreach ($dels as $itemId) {
                 $item = orderItem::get($itemId);
                 if ($item instanceof orderItem) {
                     $order->removeItem($item);
                     $isChanged = true;
                 }
             }
         }
         if ($isChanged) {
             $order->refresh();
             $order->commit();
         }
         if ($oldDeliveryPrice != $newDeliveryPrice && !$isChanged) {
             $originalPrice = $object->getValue('total_original_price');
             $totalPrice = $originalPrice;
             $discount = $order->getDiscount();
             if ($discount instanceof discount) {
                 $totalPrice = $discount->recalcPrice($originalPrice);
             }
             $totalPrice += $newDeliveryPrice;
             $object->setValue('total_price', $totalPrice);
             $object->commit();
         }
         $this->chooseRedirect();
     }
     $this->setDataType("form");
     $this->setActionType("modify");
     $data = $this->prepareData($inputData, "object");
     $this->setData($data);
     return $this->doData();
 }
Example #2
0
		protected function mergeBasket(umiObject $guestBasket) {
			$orderItems = $guestBasket->order_items;

			if(is_array($orderItems)) {
				$userBasket = __emarket_purchasing::getBasketOrder(false);

				if($userBasket) {
					foreach($orderItems as $orderItemId) {
						$orderItem = orderItem::get($orderItemId);
						if($orderItem) {
							$userBasket->appendItem($orderItem);
						}
					}
					$userBasket->commit();
				}
			}

			$guestBasket->delete();
		}
Example #3
0
 /**
  * Загрузить список наименований в заказе из объекта заказа
  */
 protected function readItems()
 {
     $objectItems = $this->object->order_items;
     $items = array();
     foreach ($objectItems as $objectId) {
         try {
             $items[] = orderItem::get($objectId);
         } catch (privateException $e) {
         }
     }
     $this->items = $items;
 }
 /**
  * Возвращает элемент корзины по Id товара с которым связан элемент.
  * @param Integer $elementId
  * @param Boolean $autoCreate - Создавать ли элемент корзины если не существует.
  */
 public function getBasketItem($elementId, $autoCreate = true)
 {
     $order = self::getBasketOrder();
     $orderItems = $order->getItems();
     foreach ($orderItems as $orderItem) {
         $element = $orderItem->getItemElement();
         if ($element instanceof umiHierarchyElement) {
             if ($element->getId() == $elementId) {
                 return $orderItem;
             }
         }
     }
     return $autoCreate ? orderItem::create($elementId) : null;
 }
Example #5
0
		public function refresh() {
			$this->price = $this->getElementPrice();
			
			$element = $this->getItemElement();
			if($element instanceof iUmiHierarchyElement) {
				$name = $element->getName();
				
				$options = array();
				$objects = umiObjectsCollection::getInstance();
				foreach($this->getOptions() as $optionInfo) {
					$optionId = $optionInfo['option-id'];
					$option = $objects->getObject($optionId);
					if($option instanceof iUmiObject) {
						$options[] = $option->getName();
					}
				}
				
				if(sizeof($options)) {
					$name .= ' (' . implode(", ", $options) . ')';
				}
				$this->object->setName($name);
			}
			return parent::refresh();
		}