Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
Arquivo: Cart.php Projeto: kingsj/core
 /**
  * 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
  * @param integer              $amount  Amount of product to add to cart
  *
  * @return \XLite\Model\OrderItem
  */
 protected function prepareOrderItem(\XLite\Model\Product $product, $amount)
 {
     $item = null;
     if ($product) {
         $item = new \XLite\Model\OrderItem();
         $item->setOrder($this->getCart());
         $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 ($newAmount > 0) {
             $item->setAmount($newAmount);
         } else {
             $item->setOrder(null);
             $item = null;
         }
     }
     return $item;
 }
Exemplo n.º 3
0
 /**
  * Get prepared order item by product ID
  *
  * @return array
  */
 protected function getPreparedItemByProductId()
 {
     $order = $this->getOrder();
     $request = \XLite\Core\Request::getInstance();
     $item = new \XLite\Model\OrderItem();
     $item->setOrder($order);
     $item->setProduct(\XLite\Core\Database::getRepo('XLite\\Model\\Product')->find($request->product_id));
     $attributes = $request->new;
     $attributes = reset($attributes);
     $attributeValues = array();
     if (!empty($attributes['attribute_values'])) {
         $attributeValues = $attributes['attribute_values'];
     }
     return array($item, $attributeValues);
 }