Пример #1
0
 /**
  * Parse buyRequest into options values used by product
  *
  * @param  \Magento\Framework\DataObject $buyRequest
  * @return \Magento\Framework\DataObject
  */
 public function processBuyRequest(\Magento\Framework\DataObject $buyRequest)
 {
     $options = new \Magento\Framework\DataObject();
     /* add product custom options data */
     $customOptions = $buyRequest->getOptions();
     if (is_array($customOptions)) {
         array_filter($customOptions, function ($value) {
             return $value !== '';
         });
         $options->setOptions($customOptions);
     }
     /* add product type selected options data */
     $type = $this->getTypeInstance();
     $typeSpecificOptions = $type->processBuyRequest($this, $buyRequest);
     $options->addData($typeSpecificOptions);
     /* check correctness of product's options */
     $options->setErrors($type->checkProductConfiguration($this, $buyRequest));
     return $options;
 }
Пример #2
0
 /**
  * Move quote item to another items list
  *
  * @param int|\Magento\Quote\Model\Quote\Item $item
  * @param string $moveTo
  * @param int $qty
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function moveQuoteItem($item, $moveTo, $qty)
 {
     $item = $this->_getQuoteItem($item);
     if ($item) {
         $removeItem = false;
         $moveTo = explode('_', $moveTo);
         switch ($moveTo[0]) {
             case 'order':
                 $info = $item->getBuyRequest();
                 $info->setOptions($this->_prepareOptionsForRequest($item))->setQty($qty);
                 $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->setStoreId($this->getQuote()->getStoreId())->load($item->getProduct()->getId());
                 $product->setSkipCheckRequiredOption(true);
                 $newItem = $this->getQuote()->addProduct($product, $info);
                 if (is_string($newItem)) {
                     throw new \Magento\Framework\Exception\LocalizedException(__($newItem));
                 }
                 $product->unsSkipCheckRequiredOption();
                 $newItem->checkData();
                 $this->_needCollectCart = true;
                 break;
             case 'cart':
                 $cart = $this->getCustomerCart();
                 if ($cart && is_null($item->getOptionByCode('additional_options'))) {
                     //options and info buy request
                     $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->setStoreId($this->getQuote()->getStoreId())->load($item->getProduct()->getId());
                     $info = $item->getOptionByCode('info_buyRequest');
                     if ($info) {
                         $info = new \Magento\Framework\DataObject(unserialize($info->getValue()));
                         $info->setQty($qty);
                         $info->setOptions($this->_prepareOptionsForRequest($item));
                     } else {
                         $info = new \Magento\Framework\DataObject(['product_id' => $product->getId(), 'qty' => $qty, 'options' => $this->_prepareOptionsForRequest($item)]);
                     }
                     $cartItem = $cart->addProduct($product, $info);
                     if (is_string($cartItem)) {
                         throw new \Magento\Framework\Exception\LocalizedException(__($cartItem));
                     }
                     $cartItem->setPrice($item->getProduct()->getPrice());
                     $this->_needCollectCart = true;
                     $removeItem = true;
                 }
                 break;
             case 'wishlist':
                 $wishlist = null;
                 if (!isset($moveTo[1])) {
                     $wishlist = $this->_objectManager->create('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId($this->getSession()->getCustomerId(), true);
                 } else {
                     $wishlist = $this->_objectManager->create('Magento\\Wishlist\\Model\\Wishlist')->load($moveTo[1]);
                     if (!$wishlist->getId() || $wishlist->getCustomerId() != $this->getSession()->getCustomerId()) {
                         $wishlist = null;
                     }
                 }
                 if (!$wishlist) {
                     throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t find this wish list.'));
                 }
                 $wishlist->setStore($this->getSession()->getStore())->setSharedStoreIds($this->getSession()->getStore()->getWebsite()->getStoreIds());
                 if ($wishlist->getId() && $item->getProduct()->isVisibleInSiteVisibility()) {
                     $info = $item->getBuyRequest();
                     $info->setOptions($this->_prepareOptionsForRequest($item))->setQty($qty)->setStoreId($this->getSession()->getStoreId());
                     $wishlist->addNewItem($item->getProduct(), $info);
                     $removeItem = true;
                 }
                 break;
             case 'remove':
                 $removeItem = true;
                 break;
             default:
                 break;
         }
         if ($removeItem) {
             $this->getQuote()->deleteItem($item);
         }
         $this->setRecollect(true);
     }
     return $this;
 }
Пример #3
0
 public function getRequest()
 {
     $request = new \Magento\Framework\DataObject();
     $request->setQty($this->proxyItem->getQty());
     // grouped and downloadable products doesn't have options
     if ($this->proxyItem->getProduct()->getTypeId() == TypeGrouped::TYPE_CODE || $this->proxyItem->getProduct()->getTypeId() == TypeDownloadable::TYPE_DOWNLOADABLE) {
         return $request;
     }
     /** @var $magentoProduct \Ess\M2ePro\Model\Magento\Product */
     $magentoProduct = $this->modelFactory->getObject('Magento\\Product')->setProduct($this->getProduct());
     $options = $this->proxyItem->getOptions();
     if (empty($options)) {
         return $request;
     }
     if ($magentoProduct->isSimpleType()) {
         $request->setOptions($options);
     } else {
         if ($magentoProduct->isBundleType()) {
             $request->setBundleOption($options);
         } else {
             if ($magentoProduct->isConfigurableType()) {
                 $request->setSuperAttribute($options);
             }
         }
     }
     return $request;
 }