Example #1
0
 /**
  * Allow Fixed Bundles to be added to the cart without needing to submit the add to cart form
  *
  * @param Varien_Object $buyRequest
  * @param Mage_Catalog_Model_Product $product
  * @param string $processMode
  * @return array|string
  * @author Paul Hachmang <*****@*****.**>
  */
 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
 {
     $product = $this->getProduct($product);
     $options = $buyRequest->getBundleOption();
     $optionsCollection = $this->getOptionsCollection($product);
     if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && count($options) <= 0) {
         foreach ($optionsCollection->getItems() as $option) {
             if ($option->getType() == self::OPTION_TYPE_FIXED && $option->getRequired() && !isset($options[$option->getId()])) {
                 $selectionData = Mage::getResourceSingleton('bundle/bundle')->getSelectionsData($product->getId());
                 foreach ($selectionData as $prod) {
                     $options[$option->getId()][] = $prod['selection_id'];
                 }
             }
         }
         //we are placing the new information in the request
         $buyRequest->setBundleOption($options);
     }
     return parent::_prepareProduct($buyRequest, $product, $processMode);
 }
Example #2
0
 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
 }
Example #3
0
 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;
 }
Example #4
0
 /**
  * Add new product to registry
  *
  * @param int|Mage_Sales_Model_Quote_Item $itemToAdd
  * @param Varien_Object $request
  * @return Enterprise_GiftRegistry_Model_Item
  */
 public function addItem($itemToAdd, $request = null)
 {
     if ($itemToAdd instanceof Mage_Sales_Model_Quote_Item) {
         $productId = $itemToAdd->getProductId();
         $qty = $itemToAdd->getQty();
     } else {
         $productId = $itemToAdd;
         $qty = $request && $request->getQty() ? $request->getQty() : 1;
     }
     $product = $this->getProduct($productId);
     if ($product->getTypeInstance(true)->hasRequiredOptions($product) && (!$request && !$itemToAdd instanceof Mage_Sales_Model_Quote_Item)) {
         throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS);
     }
     if ($itemToAdd instanceof Mage_Sales_Model_Quote_Item) {
         $cartCandidate = $itemToAdd->getProduct();
         $cartCandidate->setCustomOptions($itemToAdd->getOptionsByCode());
         $cartCandidates = array($cartCandidate);
     } else {
         if (!$request) {
             $request = new Varien_Object();
             $request->setBundleOption(array());
             //Bundle options mocking for compatibility
         }
         $cartCandidates = $product->getTypeInstance(true)->prepareForCart($request, $product);
     }
     if (is_string($cartCandidates)) {
         //prepare process has error, seems like we have bundle
         throw new Mage_Core_Exception($cartCandidates, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS);
     }
     $item = Mage::getModel('enterprise_giftregistry/item');
     $items = $item->getCollection()->addRegistryFilter($this->getId());
     foreach ($cartCandidates as $currentCandidate) {
         if ($currentCandidate->getParentProductId()) {
             continue;
         }
         $alreadyExists = false;
         $productId = $currentCandidate->getId();
         foreach ($items as $itemForCheck) {
             if ($itemForCheck->isRepresentProduct($currentCandidate)) {
                 $alreadyExists = true;
                 $matchedItem = $itemForCheck;
                 break;
             }
         }
         $candidateQty = $currentCandidate->getCartQty();
         if (!empty($candidateQty)) {
             $qty = $candidateQty;
         }
         if ($alreadyExists) {
             $matchedItem->setQty($matchedItem->getQty() + $qty)->save();
         } else {
             $customOptions = $currentCandidate->getCustomOptions();
             $item = Mage::getModel('enterprise_giftregistry/item');
             $item->setEntityId($this->getId())->setProductId($productId)->setOptions($customOptions)->setQty($qty)->save();
         }
     }
     return $item;
 }
Example #5
0
 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);
 }