Exemplo n.º 1
0
 /**
  * enables inheritance for field collections, if xxxInheritance field is available and set to string 'true'
  *
  * @param string $key
  * @return mixed|\Pimcore\Model\Object\Fieldcollection
  */
 public function preGetValue($key)
 {
     if ($this->getClass()->getAllowInherit() && \Pimcore\Model\Object\AbstractObject::doGetInheritedValues() && $this->getClass()->getFieldDefinition($key) instanceof \Pimcore\Model\Object\ClassDefinition\Data\Fieldcollections) {
         $checkInheritanceKey = $key . "Inheritance";
         if ($this->{'get' . $checkInheritanceKey}() == "true") {
             $parentValue = $this->getValueFromParent($key);
             $data = $this->{$key};
             if (!$data) {
                 $data = $this->getClass()->getFieldDefinition($key)->preGetData($this);
             }
             if (!$data) {
                 return $parentValue;
             } else {
                 if (!empty($parentValue)) {
                     $value = new \Pimcore\Model\Object\Fieldcollection($parentValue->getItems());
                     if (!empty($data)) {
                         foreach ($data as $entry) {
                             $value->add($entry);
                         }
                     }
                 } else {
                     $value = new \Pimcore\Model\Object\Fieldcollection($data->getItems());
                 }
                 return $value;
             }
         }
     }
     return parent::preGetValue($key);
 }
Exemplo n.º 2
0
 /**
  * @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;
 }