/**
  * Define specific data structure which will be sent in the triggering event (model.selected)
  *
  * @param mixed $item Model item
  *
  * @return string
  */
 protected function defineDataItem($item)
 {
     $data = parent::defineDataItem($item);
     $orderItem = new \XLite\Model\OrderItem();
     $orderItem->setProduct($item);
     if ($item->hasEditableAttributes()) {
         $orderItem->setAttributeValues($item->prepareAttributeValues());
     }
     $orderItem = $this->postprocessOrderItem($orderItem);
     $orderItem->setItemNetPrice(null);
     $orderItem->setPrice(null);
     $orderItem->calculate();
     $orderItem->renew();
     $data['clear_price'] = $orderItem->getClearPrice();
     $data['selected_price'] = $orderItem->getDisplayPrice();
     $data['max_qty'] = $orderItem->getProductAvailableAmount();
     $data['server_price_control'] = $orderItem->isPriceControlledServer();
     if ($item->hasEditableAttributes()) {
         // SKU may differ after attributes selection
         $data['selected_sku'] = $orderItem->getSku();
         $data['presentation'] = $this->formatItem($orderItem);
         $data['clear_price'] = $orderItem->getClearPrice();
         $data['server_price_control'] = $orderItem->isPriceControlledServer();
         if ($data['server_price_control']) {
             $data['selected_price'] = $orderItem->getDisplayPrice();
         }
         $widget = new \XLite\View\OrderItemAttributes(array('orderItem' => $orderItem, 'idx' => \XLite\Core\Request::getInstance()->idx ?: $orderItem->getItemId()));
         $widget->init();
         $data['selected_attributes'] = $widget->getContent();
         $widget = new \XLite\View\InvoiceAttributeValues(array('item' => $orderItem, 'displayVariative' => 1));
         $widget->init();
         $data['attributes_widget'] = $widget->getContent();
     }
     $this->orderItem = $orderItem;
     return $data;
 }
Exemple #2
0
 /**
  * Prepare order item class for adding to cart.
  * This method takes \XLite\Model\Product class and amount and creates \XLite\Model\OrderItem.
  * This order item container will be added to cart in $this->addItem() method.
  *
  * @param \XLite\Model\Product $product Product class to add to cart OPTIOANL
  * @param integer              $amount  Amount of product to add to cart OPTIONAL
  *
  * @return \XLite\Model\OrderItem
  */
 protected function prepareOrderItem(\XLite\Model\Product $product = null, $amount = null)
 {
     $item = null;
     if ($product) {
         $item = new \XLite\Model\OrderItem();
         $item->setOrder($this->getCart());
         $item->setAttributeValues($product->prepareAttributeValues(\XLite\Core\Request::getInstance()->attribute_values));
         $item->setProduct($product);
         // We make amount correction if there is no such product with additional specifications
         // which are provided in order item container
         $newAmount = $this->correctAmountToAdd($item, $amount);
         if (0 < $newAmount) {
             $item->setAmount($newAmount);
         } else {
             $item->setOrder(null);
             $item = null;
         }
     }
     return $item;
 }