public function getRequest() { $request = new Varien_Object(); $request->setQty($this->proxyItem->getQty()); // grouped and downloadable products doesn't have options if ($this->proxyItem->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED || $this->proxyItem->getProduct()->getTypeId() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) { return $request; } /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */ $magentoProduct = Mage::getModel('M2ePro/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; }
protected function _addProductsToQuote($productInCardList, $paramsArray) { $productInCardList = $this->_concatenateProductsInQuote($productInCardList); foreach ($productInCardList as $productItem) { $product = Mage::getModel('catalog/product')->load($productItem['id']); if (!$product->getId()) { throw new LogicException('Product does not exist. Probably it was deleted.'); } if ($product->getStatus() === Mage_Catalog_Model_Product_Status::STATUS_DISABLED) { throw new LogicException('Product is disabled.'); } $productTypeId = $product->getTypeId(); if ($productTypeId == Ess_M2ePro_Model_MagentoProduct::TYPE_GROUPED) { // Grouped product converted to assigned simple if (!isset($productItem['options'])) { throw new LogicException('The item does not have options. At the current version, Order Import for grouped product supports only multi variation listing.'); } $product = $this->_getRelatedProductFromGroupedForEbayData($product, $productItem); if (is_null($product)) { throw new LogicException('There is no associated products found for grouped product.'); } else { $productTypeId = $product->getTypeId(); } } $productItem['price'] = $this->_getConvertedPrice($productItem['price']); $request = new Varien_Object(); $request->setQty($productItem['qty']); switch ($productTypeId) { case Ess_M2ePro_Model_MagentoProduct::TYPE_SIMPLE: $haveRequiredOptionsInstant = $product->getTypeInstance(true)->hasRequiredOptions($product); $haveRequiredOptions = $product->hasRequiredOptions(); if ($haveRequiredOptions && !$product->getRequiredOptions()) { $haveRequiredOptions = false; // important: possible incorect behavior } if ($haveRequiredOptionsInstant || $haveRequiredOptions || $this->_checkSimpleProductHasRequiredCustomOptions($product)) { $customOptionsData = array(); if (isset($productItem['options']) && count($productItem['options'])) { // Have multivariation data for simple product // Use to set Custom Options data $customOptionsData = $this->_getCustomOptionsForEbayData($productItem); $this->_addNotifyMessage('Product has <b>Required Options</b>. Selected Options Values are taken from eBay Multi Variation Data'); } else { // No multivariation data, set first required option $customOptionsData = $this->_getRandomCustomOptions($productItem); $this->_addNotifyMessage('Product has <b>Required Options</b>. First option value is selected.'); } $request->setOptions($customOptionsData['options']); // Dec price for percent change (after apply percent price inc = need price) $productItem['price'] = $productItem['price'] / (1 + $customOptionsData['price_change_percent'] / 100); // Change for custom options price. price_change_fixed low that 0 when option inc price, more 0 - when inc $productItem['price'] += $customOptionsData['price_change_fixed'] / (1 + $customOptionsData['price_change_percent'] / 100); } // end of $haveRequriedOptions break; case Ess_M2ePro_Model_MagentoProduct::TYPE_CONFIGURABLE: if (!isset($productItem['options'])) { throw new LogicException('The item does not have options. At the current version, Order Import for configurable product supports only multi variation listing.'); } $configurableOptions = $this->_getConfigurableAttributeForEbayData($productItem); // Set selected attributes $request->setSuperAttribute($configurableOptions['options']); // Each option value can change total price value, remove // this changes for equal: order price = eBay sold price $productItem['price'] += $configurableOptions['price_change']; break; case Ess_M2ePro_Model_MagentoProduct::TYPE_BUNDLE: if (!isset($productItem['options'])) { throw new LogicException('The item does not have options. At the current version, Order Import for bundle product supports only multi variation listing.'); } $bundleOptions = $this->_getBundleOptionsForEbayData($productItem); $request->setBundleOption($bundleOptions['options']); // $bundleQty = array(); // foreach ($bundleOptions['options'] as $optionId => $optionValue) { // $bundleQty[$optionId] = $productItem['qty']; // } // $request->setBundleOptionQty($bundleQty); // $request->setQty(1); $this->_addNotifyMessage('Price for Bundle item is taken from Magento store.'); break; default: throw new LogicException('At the current version, Order Import does not support product type: ' . $productTypeId . ''); } $product->setPrice($productItem['price']); $product->setSpecialPrice($productItem['price']); $this->_initProductTaxClassId($product, $paramsArray['taxPercent']); $result = $this->_quote->addProduct($product, $request); if (is_string($result)) { throw new Exception($result); } // TODO: ugly hack //if ($productTypeId == Ess_M2ePro_Model_MagentoProduct::TYPE_BUNDLE || // Ess_M2ePro_Model_MagentoProduct::TYPE_CONFIGURABLE || // Ess_M2ePro_Model_MagentoProduct::TYPE_GROUPED) { foreach ($paramsArray['products'] as $tempProduct) { if ($tempProduct['id'] == $product->getId()) { $tempQuoteItem = $this->_quote->getItemByProduct($product); if ($tempQuoteItem !== false) { $tempQuoteItem->setNoDiscount(1); $tempQuoteItem->setOriginalCustomPrice($this->_getConvertedPrice($tempProduct['price'])); } break; } } //} } // foreach $productInCardList }
protected function addProductToQuote(Mage_Catalog_Model_Product $product, Ess_M2ePro_Model_Orders_OrderItem $item) { /** @var $magentoProduct Ess_M2ePro_Model_MagentoProduct */ $magentoProduct = Mage::getModel('M2ePro/MagentoProduct')->setProduct($product); if (!$magentoProduct->isSimpleType() && !$magentoProduct->isGroupedType() && !$magentoProduct->isConfigurableType() && !$magentoProduct->isBundleType()) { // Parser hack -> Mage::helper('M2ePro')->__('Order Import does not support product type: %type%.') $tempMessageException = 'Order Import does not support product type: %type%.'; throw new Exception(str_replace('%type%', $product->getTypeId(), $tempMessageException)); } $request = new Varien_Object(); // Prepare item options // ------------ $ebayItemOptions = $item->getOptions(true); $tempEbayItemOptions = array(); foreach ($ebayItemOptions as $key => $value) { $tempEbayItemOptions[trim(strtolower($key))] = trim(strtolower($value)); } // ------------ if ($magentoProduct->isSimpleType()) { $options = $this->getSimpleProductOptions($magentoProduct, $tempEbayItemOptions); if (count($options)) { $request->setOptions($options); } } if ($magentoProduct->isGroupedType()) { $product = $this->getRelatedGroupedProduct($magentoProduct, $tempEbayItemOptions); if (!$product || !$product->getId()) { throw new LogicException('There is no associated products found for grouped product.'); } } if ($magentoProduct->isConfigurableType()) { $request->setSuperAttribute($this->getConfigurableProductOptions($magentoProduct, $tempEbayItemOptions)); } if ($magentoProduct->isBundleType()) { // non-default store may not work for bundle product options //$product->setStoreId(Mage::helper('M2ePro/Sales')->getDefaultStoreId()); $product->setStoreId($this->_magentoQuote->getStoreId()); $request->setBundleOption($this->getBundleProductOptions($magentoProduct, $tempEbayItemOptions)); } $request->setQty($item->getData('qty_purchased')); $price = $this->getPrice($item); $product->setPrice($price); $product->setSpecialPrice($price); $product->setTaxClassId($this->getProductTaxClassId($product)); return $this->_magentoQuote->addProduct($product, $request); }