protected function updateOfferItem(OnlineShop_Framework_ICartItem $cartItem, OnlineShop_OfferTool_AbstractOfferItem $offerItem) { $offerItem->setAmount($cartItem->getCount()); $offerItem->setProduct($cartItem->getProduct()); if ($offerItem->getProduct()) { $offerItem->setProductName($cartItem->getProduct()->getOSName()); $offerItem->setProductNumber($cartItem->getProduct()->getOSProductNumber()); } $offerItem->setComment($cartItem->getComment()); $price = 0; if ($cartItem->getTotalPrice()) { $price = $cartItem->getTotalPrice()->getAmount(); } $price = $this->priceTransformationHook($price); if ($price != $offerItem->getOriginalTotalPrice()) { $offerItem->setOriginalTotalPrice($price); $offerItem->setFinalTotalPrice($price); } //Delete all subitems and add them as new items $offerSubItems = $offerItem->getSubItems(); foreach ($offerSubItems as $i) { $i->delete(); } $subItems = $cartItem->getSubItems(); if (!empty($subItems)) { $offerSubItems = array(); foreach ($subItems as $subItem) { $offerSubItem = $this->createOfferItem($subItem, $offerItem); $offerSubItem->save(); $offerSubItems[] = $offerSubItem; } $offerItem->setSubItems($offerSubItems); } $offerItem->save(); return $offerItem; }
/** * @param \OnlineShop_Framework_ICartItem $item * @param OnlineShop_Framework_AbstractOrder |OnlineShop_Framework_AbstractOrderItem $parent * * @return OnlineShop_Framework_AbstractOrderItem * @throws Exception * @throws OnlineShop_Framework_Exception_UnsupportedException */ protected function createOrderItem(OnlineShop_Framework_ICartItem $item, $parent) { $orderItemListClass = $this->orderItemClass . "_List"; if (!class_exists($orderItemListClass)) { throw new Exception("Class {$orderItemListClass} does not exist."); } $key = \Pimcore\File::getValidFilename($item->getProduct()->getId() . "_" . $item->getItemKey()); $orderItemList = new $orderItemListClass(); $orderItemList->setCondition("o_parentId = ? AND o_key = ?", array($parent->getId(), $key)); $orderItems = $orderItemList->load(); if (count($orderItems) > 1) { throw new Exception("No unique order item found for {$key}."); } if (count($orderItems) == 1) { $orderItem = $orderItems[0]; } else { $orderItem = $this->getNewOrderItemObject(); $orderItem->setParent($parent); $orderItem->setPublished(true); $orderItem->setKey($key); } $orderItem->setAmount($item->getCount()); $orderItem->setProduct($item->getProduct()); if ($item->getProduct()) { $orderItem->setProductName($item->getProduct()->getOSName()); $orderItem->setProductNumber($item->getProduct()->getOSProductNumber()); } $orderItem->setComment($item->getComment()); $price = 0; if (is_object($item->getTotalPrice())) { $price = $item->getTotalPrice()->getAmount(); } $orderItem->setTotalPrice($price); // save active pricing rules $priceInfo = $item->getPriceInfo(); if ($priceInfo instanceof OnlineShop_Framework_Pricing_IPriceInfo && method_exists($orderItem, 'setPricingRules')) { $priceRules = new \Pimcore\Model\Object\Fieldcollection(); foreach ($priceInfo->getRules() as $rule) { $priceRule = new \Pimcore\Model\Object\Fieldcollection\Data\PricingRule(); $priceRule->setRuleId($rule->getId()); $priceRule->setName($rule->getName()); $priceRules->add($priceRule); } $orderItem->setPricingRules($priceRules); $orderItem->save(); } return $orderItem; }