/** * @param OnlineShop_Framework_ICartItem $item * @param $parent * @return OnlineShop_OfferTool_AbstractOfferItem */ protected function createOfferItem(OnlineShop_Framework_ICartItem $item, $parent) { $offerItem = $this->getNewOfferItemObject(); $offerItem->setParent($parent); $offerItem->setPublished(true); $offerItem->setCartItemKey($item->getItemKey()); $offerItem->setKey($item->getProduct()->getId() . "_" . $item->getItemKey()); $offerItem->setAmount($item->getCount()); $offerItem->setProduct($item->getProduct()); if ($item->getProduct()) { $offerItem->setProductName($item->getProduct()->getOSName()); $offerItem->setProductNumber($item->getProduct()->getOSProductNumber()); } $offerItem->setComment($item->getComment()); $price = 0; if ($item->getTotalPrice()) { $price = $item->getTotalPrice()->getAmount(); } $price = $this->priceTransformationHook($price); $offerItem->setOriginalTotalPrice($price); $offerItem->setFinalTotalPrice($price); $offerItem->save(); $subItems = $item->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; }