Example #1
0
 /**
  * Set qty and custom price for quote item
  *
  * @param Item $item
  * @param \Magento\Framework\Object $request
  * @param Product $candidate
  * @return void
  */
 public function prepare(Item $item, Object $request, Product $candidate)
 {
     /**
      * We specify qty after we know about parent (for stock)
      */
     if ($request->getResetCount() && !$candidate->getStickWithinParent() && $item->getId() == $request->getId()) {
         $item->setData(CartItemInterface::KEY_QTY, 0);
     }
     $item->addQty($candidate->getCartQty());
     $customPrice = $request->getCustomPrice();
     if (!empty($customPrice)) {
         $item->setCustomPrice($customPrice);
         $item->setOriginalCustomPrice($customPrice);
     }
 }
Example #2
0
 /**
  * Check product representation in item
  *
  * @param   \Magento\Catalog\Model\Product $product
  * @return  bool
  */
 public function representProduct($product)
 {
     $itemProduct = $this->getProduct();
     if (!$product || $itemProduct->getId() != $product->getId()) {
         return false;
     }
     /**
      * Check maybe product is planned to be a child of some quote item - in this case we limit search
      * only within same parent item
      */
     $stickWithinParent = $product->getStickWithinParent();
     if ($stickWithinParent) {
         if ($this->getParentItem() !== $stickWithinParent) {
             return false;
         }
     }
     // Check options
     $itemOptions = $this->getOptionsByCode();
     $productOptions = $product->getCustomOptions();
     if (!$this->compareOptions($itemOptions, $productOptions)) {
         return false;
     }
     if (!$this->compareOptions($productOptions, $itemOptions)) {
         return false;
     }
     return true;
 }