public static function createFromOrderedItem(OrderedItem $item) { if (!($product = $item->getProduct())) { return; } $instance = self::createFromArray($product->toArray()); $instance->setCount($item->getCount()); $instance->setItemPrice($item->getPrice()); return $instance; }
/** * Get per item charge for particular item depending on its shipping class */ public function getItemCharge(OrderedItem $item) { $product = $item->getProduct()->getParent(); if (!$product->isLoaded()) { $product->load(); } $class = $product->shippingClass->get(); if (!$class) { return $this->perItemCharge->get(); } $charge = $this->getValueByLang('perItemChargeClass', $class->getID()); if (is_null($charge) || !strlen($charge)) { return $this->perItemCharge->get(); } return $charge; }
private function getGroupPrice(OrderedItem $item, $groupID, $rules) { $itemCnt = 0; // include other variations of the same product? if ($parent = $item->getProduct()->parent->get()) { $order = $item->customerOrder->get(); foreach ($order->getShoppingCartItems() as $orderItem) { if ($orderItem->isVariationDiscountsSummed()) { $orderProduct = $orderItem->product->get()->getParent(); if ($orderProduct->getID() == $parent->getID()) { $itemCnt += $orderItem->count->get(); } } } } if (!$itemCnt) { $itemCnt = $item->count->get(); } // include past orders $dateRange = $item->isPastOrdersInQuantityPrices(); if (!is_null($dateRange)) { $from = $dateRange ? strtotime('now -' . (int) $dateRange . ' days') : 0; $orders = $item->customerOrder->get()->getBusinessRuleContext()->getPastOrdersBetween($from, time()); $id = $item->getProduct()->getID(); foreach ($orders as $order) { foreach ($order->getPurchasedItems() as $i) { $product = $i->getProduct(); if ($id == $product['ID']) { $itemCnt += $i->getCount(); } } } } return self::getProductGroupPrice($groupID, $rules, $itemCnt); }
public function updateCount(OrderedItem $item, $count) { $item->count->set($this->validateCount($item->getProduct(), $count)); }
private function getItemResponse(OrderedItem $item) { $item->customerOrder->get()->load(); $item->customerOrder->get()->loadItems(); if ($image = $item->getProduct()->defaultImage->get()) { $image->load(); } $this->application->getLocale()->translationManager()->loadFile('backend/Shipment'); $response = new ActionResponse('item', $item->toArray()); // load product options and variations $response->set('allOptions', ProductOption::loadOptionsForProductSet($item->getProduct()->getParent()->initSet())); $response->set('variations', $item->getProduct()->getParent()->initSet()->getVariationData($this->application)); return $response; }