/** * Test hasRedirectOptions * * @dataProvider redirectOptionsDataProvider */ public function testHasRedirectOptions($option, $expected) { $helper = new Mage_Core_Helper_Url_Rewrite(); $mockObject = new Varien_Object(); $mockObject->setOptions($option); $this->assertEquals($expected, $helper->hasRedirectOptions($mockObject)); }
public function outputAction() { $pear = Varien_Pear::getInstance(); $input = $this->getRequest()->getParam('argv'); $argv = preg_split('#\\s+#', $input); $command = false; $options = array(); $params = array(); foreach ($argv as $arg) { if ($arg[0] === '-') { $opt = ''; if ($arg[1] === '-') { $opt = substr($arg, 2); } if ($opt) { $options[$opt] = 1; } } elseif (empty($command)) { $command = $arg; } else { $params[] = $arg; } } $run = new Varien_Object(); if ($command) { $run->setComment(Mage::helper('adminhtml')->__('Running:') . ' "' . $input . '"' . "\r\n\r\n"); $run->setCommand($command); $run->setOptions($options); $run->setParams($params); } else { $run->setComment(Mage::helper('adminhtml')->__('Invalid input:') . ' "' . $input . '"' . "\r\n\r\n"); } $pear->runHtmlConsole($run); }
/** * Return buyRequest object (with custom options) for order item * * @param Mage_Sales_Model_Order_Item $item * @return Varien_Object */ public function getBuyRequestFromOrderItem(Mage_Sales_Model_Order_Item $item) { $buyRequest = new Varien_Object(); $_options = array(); foreach ($this->_getItemOptions($item) as $_option) { if ($_option['option_type'] === 'file') { $_option['option_value'] = unserialize($_option['option_value']); } $_options[$_option['option_id']] = $_option['option_value']; } $buyRequest->setOptions($_options); return $buyRequest; }
/** * Parse buyRequest into options values used by product * * @param Varien_Object $buyRequest * @return Varien_Object */ public function processBuyRequest(Varien_Object $buyRequest) { $options = new Varien_Object(); /* add product custom options data */ $customOptions = $buyRequest->getOptions(); if (is_array($customOptions)) { foreach ($customOptions as $key => $value) { if ($value === '') { unset($customOptions[$key]); } } $options->setOptions($customOptions); } /* add product type selected options data */ $type = $this->getTypeInstance(true); $typeSpecificOptions = $type->processBuyRequest($this, $buyRequest); $options->addData($typeSpecificOptions); /* check correctness of product's options */ $options->setErrors($type->checkProductConfiguration($this, $buyRequest)); return $options; }
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 }
/** * Move quote item to another items list * * @param int|Mage_Sales_Model_Quote_Item $item * @param string $moveTo * @param int $qty * @return Mage_Adminhtml_Model_Sales_Order_Create */ 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 = Mage::getModel('catalog/product')->setStoreId($this->getQuote()->getStoreId())->load($item->getProduct()->getId()); $product->setSkipCheckRequiredOption(true); $newItem = $this->getQuote()->addProduct($product, $info); if (is_string($newItem)) { Mage::throwException($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 = Mage::getModel('catalog/product')->setStoreId($this->getQuote()->getStoreId())->load($item->getProduct()->getId()); $info = $item->getOptionByCode('info_buyRequest'); if ($info) { $info = new Varien_Object(unserialize($info->getValue())); $info->setQty($qty); $info->setOptions($this->_prepareOptionsForRequest($item)); } else { $info = new Varien_Object(array('product_id' => $product->getId(), 'qty' => $qty, 'options' => $this->_prepareOptionsForRequest($item))); } $cartItem = $cart->addProduct($product, $info); if (is_string($cartItem)) { Mage::throwException($cartItem); } $cartItem->setPrice($item->getProduct()->getPrice()); $this->_needCollectCart = true; $removeItem = true; } break; case 'wishlist': $wishlist = null; if (!isset($moveTo[1])) { $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($this->getSession()->getCustomer(), true); } else { $wishlist = Mage::getModel('wishlist/wishlist')->load($moveTo[1]); if (!$wishlist->getId() || $wishlist->getCustomerId() != $this->getSession()->getCustomerId()) { $wishlist = null; } } if (!$wishlist) { Mage::throwException(Mage::helper('wishlist')->__('Could not find wishlist')); } $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; }
/** * Fetch new orders from ChannelEngine. * Ran by cron. The cronjob is set in extension config file. * * @return bool */ public function fetchNewOrders() { /** * Check if client is initialized */ if (is_null($this->_client)) { return false; } foreach ($this->_client as $storeId => $_client) { /** * Retrieve new orders */ $orders = $_client->getOrders(array(Tritac_ChannelEngineApiClient_Enums_OrderStatus::NEW_ORDER)); /** * Check new orders existing */ if (is_null($orders) || $orders->count() == 0) { continue; } Mage::log("Received {$orders->count()} orders from ChannelEngine."); foreach ($orders as $order) { $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); if (empty($billingAddress)) { continue; } $lines = $order->getLines(); if (!empty($lines)) { // Initialize new quote $quote = Mage::getModel('sales/quote')->setStoreId($storeId); foreach ($lines as $item) { $productNo = $item->getMerchantProductNo(); $ids = explode('_', $productNo); $productId = $ids[0]; $productOptions = array(); if (count($ids) == 3) { $productOptions = array($ids[1] => intval($ids[2])); } // Load magento product $_product = Mage::getModel('catalog/product')->setStoreId($storeId); $_product->load($productId); if (!$_product->getId()) { // If the product can't be found by ID, fall back on the SKU. $productId = $_product->getIdBySku($productNo); $_product->load($productId); } // Prepare product parameters for quote $params = new Varien_Object(); $params->setQty($item->getQuantity()); $params->setOptions($productOptions); // Add product to quote try { $_quoteItem = $quote->addProduct($_product, $params); if (is_string($_quoteItem)) { // Magento sometimes returns a string when the method fails. -_-" Mage::throwException('Failed to create quote item: ' . $_quoteItem); } $_quoteItem->setChannelengineOrderLineId($item->getId()); } catch (Exception $e) { Mage::getModel('adminnotification/inbox')->addCritical("An order (#{$order->getId()}) could not be imported", "Reason: {$e->getMessage()} Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792"); Mage::logException($e); continue 2; } } } $phone = $order->getPhone(); if (empty($phone)) { $phone = '-'; } // Prepare billing and shipping addresses $billingData = array('firstname' => $billingAddress->getFirstName(), 'lastname' => $billingAddress->getLastName(), 'email' => $order->getEmail(), 'telephone' => $phone, 'country_id' => $billingAddress->getCountryIso(), 'postcode' => $billingAddress->getZipCode(), 'city' => $billingAddress->getCity(), 'street' => $billingAddress->getStreetName() . ' ' . $billingAddress->getHouseNr() . $billingAddress->getHouseNrAddition()); $shippingData = array('firstname' => $shippingAddress->getFirstName(), 'lastname' => $shippingAddress->getLastName(), 'email' => $order->getEmail(), 'telephone' => $phone, 'country_id' => $shippingAddress->getCountryIso(), 'postcode' => $shippingAddress->getZipCode(), 'city' => $shippingAddress->getCity(), 'street' => $shippingAddress->getStreetName() . ' ' . $shippingAddress->getHouseNr() . $shippingAddress->getHouseNrAddition()); // Register shipping cost. See Tritac_ChannelEngine_Model_Carrier_Channelengine::collectrates(); Mage::register('channelengine_shipping_amount', floatval($order->getShippingCostsInclVat())); // Set this value to make sure ChannelEngine requested the rates and not the frontend // because the shipping method has a fallback on 0,- and this will make it show up on the frontend Mage::register('channelengine_shipping', true); $quote->getBillingAddress()->addData($billingData); $quote->getShippingAddress()->addData($shippingData)->setSaveInAddressBook(0)->setCollectShippingRates(true)->setShippingMethod('channelengine_channelengine'); $quote->collectTotals(); // Set guest customer $quote->setCustomerId(null)->setCustomerEmail($quote->getBillingAddress()->getEmail())->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); // Set custom payment method $quote->setIsSystem(true); $quote->getPayment()->importData(array('method' => 'channelengine')); // Save quote and convert it to new order try { $quote->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); } catch (Exception $e) { Mage::getModel('adminnotification/inbox')->addCritical("An order (#{$order->getId()}) could not be imported", "Reason: {$e->getMessage()} Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792"); Mage::logException($e); continue; } $_order = $service->getOrder(); if ($_order->getIncrementId()) { /** * Create new invoice and save channel order */ try { // Initialize new invoice model $invoice = Mage::getModel('sales/service_order', $_order)->prepareInvoice(); // Add comment to invoice $invoice->addComment("Order paid on the marketplace.", false, true); // Register invoice. Register invoice items. Collect invoice totals. $invoice->register(); $invoice->getOrder()->setIsInProcess(true); // Initialize new channel order $_channelOrder = Mage::getModel('channelengine/order'); $_channelOrder->setOrderId($_order->getId())->setChannelOrderId($order->getId())->setChannelName($order->getChannelName())->setDoSendMails($order->getDoSendMails())->setCanShipPartial($order->getCanShipPartialOrderLines()); $invoice->getOrder()->setCanShipPartiallyItem($order->getCanShipPartialOrderLines())->setCanShipPartially($order->getCanShipPartialOrderLines()); // Start new transaction $transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder())->addObject($_channelOrder); $transactionSave->save(); } catch (Exception $e) { Mage::getModel('adminnotification/inbox')->addCritical("An invoice could not be created (order #{$_order->getIncrementId()}, channel order #{$order->getId()})", "Reason: {$e->getMessage()} Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792"); Mage::logException($e); continue; } Mage::log("Order #{$_order->getIncrementId()} was imported successfully."); } else { Mage::log("An order (#{$order->getId()}) could not be imported"); } } } return true; }
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; }
/** * Move quote item to another items store * * @param mixed $item * @param string $mogeTo * @return Mage_Adminhtml_Model_Sales_Order_Create */ public function moveQuoteItem($item, $moveTo, $qty) { if ($item = $this->_getQuoteItem($item)) { switch ($moveTo) { case 'order': $info = array(); if ($info = $item->getOptionByCode('info_buyRequest')) { $info = new Varien_Object(unserialize($info->getValue())); $info->setOptions($this->_prepareOptionsForRequest($item)); } $product = Mage::getModel('catalog/product')->setStoreId($this->getQuote()->getStoreId())->load($item->getProduct()->getId()); $product->setSkipCheckRequiredOption(true); $newItem = $this->getQuote()->addProduct($product, $info); if (is_string($newItem)) { Mage::throwException($newItem); } $product->unsSkipCheckRequiredOption(); $newItem->checkData(); $newItem->setQty($qty); break; case 'cart': if (($cart = $this->getCustomerCart()) && is_null($item->getOptionByCode('additional_options'))) { //options and info buy request $product = Mage::getModel('catalog/product')->setStoreId($this->getQuote()->getStoreId())->load($item->getProduct()->getId()); $product->setSkipCheckRequiredOption(true); $info = array(); if ($info = $item->getOptionByCode('info_buyRequest')) { $info = new Varien_Object(unserialize($info->getValue())); $info->setOptions($this->_prepareOptionsForRequest($item)); } else { $info = new Varien_Object(array('product_id' => $product->getId(), 'qty' => $qty, 'options' => $this->_prepareOptionsForRequest($item))); } $cartItem = $cart->addProduct($product, $info); if (is_string($cartItem)) { Mage::throwException($cartItem); } $product->unsSkipCheckRequiredOption(); $cartItem->setQty($qty); $cartItem->setPrice($item->getProduct()->getPrice()); $cart->collectTotals()->save(); } break; case 'wishlist': if ($wishlist = $this->getCustomerWishlist()) { $wishlist->addNewItem($item->getProduct()->getId()); } break; case 'comparelist': break; default: break; } $this->getQuote()->removeItem($item->getId()); $this->setRecollect(true); } return $this; }
/** * Return html for control element * * @return string */ public function getValuesHtml() { //mage::d($this->getRequest()->getRequestedActionName()); die; $_option = $this->getOption(); $title = null; switch ($_option->getSku()) { case 'pupil_distance': $title = '63 (average)'; break; case 'sphere_left': case 'sphere_right': $title = '0.00'; break; case 'cylinder_left': case 'cylinder_right': $title = '0.00'; break; case 'axis_left': case 'axis_right': $title = '0'; break; case 'nearadd_left': case 'nearadd_right': $title = '+0.00'; break; default: $title = ''; } if (($title || $title === '0') && $this->getRequest()->getRequestedActionName() !== 'configure') { foreach ($_option->getValues() as $value) { if ($value->getTitle() == $title) { $predefined = new Varien_Object(); $predefined->setOptions(array($_option->getId() => $value->getOptionTypeId())); $this->getProduct()->setPreconfiguredValues($predefined); } } } $configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $_option->getId()); // #mage::D($this->getProduct()->getPreconfiguredValues()); $store = $this->getProduct()->getStore(); if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN || $_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) { $require = $_option->getIsRequire() ? ' required-entry' : ''; $extraParams = ''; $select = $this->getLayout()->createBlock('core/html_select')->setData(array('id' => 'select_' . $_option->getId(), 'class' => $require . ' product-custom-option ', 'title' => $_option->getSku())); if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN) { $select->setName('options[' . $_option->getid() . ']'); //->addOption('', $this->__('-- Please Select --')); } else { $select->setName('options[' . $_option->getid() . '][]'); $select->setClass('multiselect' . $require . ' product-custom-option'); } foreach ($_option->getValues() as $_value) { $priceStr = $this->_formatPrice(array('is_percent' => $_value->getPriceType() == 'percent', 'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent')), false); $select->addOption($_value->getOptionTypeId(), $_value->getTitle() . ' ' . $priceStr . '', array('price' => $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false), 'sku' => $_value->getSku())); } if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) { $extraParams = ' multiple="multiple"'; } if (!$this->getSkipJsReloadPrice()) { $extraParams .= ' onchange="opConfig.reloadPrice()"'; } $select->setExtraParams($extraParams); if ($configValue) { $select->setValue($configValue); } return $select->getHtml(); } if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO || $_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX) { $selectHtml = '<ul id="options-' . $_option->getId() . '-list" class="options-list">'; $require = $_option->getIsRequire() ? ' validate-one-required-by-name' : ''; $arraySign = ''; switch ($_option->getType()) { case Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO: $type = 'radio'; $class = 'radio'; /*if (!$_option->getIsRequire()) { $selectHtml .= '<li><input type="radio" id="options_' . $_option->getId() . '" class="' . $class . ' product-custom-option" name="options[' . $_option->getId() . ']"' . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') . ' value="" checked="checked" /><span class="label"><label for="options_' . $_option->getId() . '">' . $this->__('None') . '</label></span></li>'; }*/ break; case Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX: $type = 'checkbox'; $class = 'checkbox'; $arraySign = '[]'; break; } $count = 1; foreach ($_option->getValues() as $_value) { $count++; $priceStr = $this->_formatPrice(array('is_percent' => $_value->getPriceType() == 'percent', 'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent'))); $htmlValue = $_value->getOptionTypeId(); if ($arraySign) { $checked = is_array($configValue) && in_array($htmlValue, $configValue) ? 'checked' : ''; } else { $checked = $configValue == $htmlValue ? 'checked' : ''; } if (1 == count($_option->getValues())) { $checked = 'checked'; } $selectHtml .= '<li>' . '<input type="' . $type . '" sku="' . $_value->getSku() . '" class="' . $class . ' ' . $require . ' product-custom-option ' . $_value->getSku() . '"' . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') . ' name="options[' . $_option->getId() . ']' . $arraySign . '" id="options_' . $_option->getId() . '_' . $count . '" value="' . $htmlValue . '" ' . $checked . ' price="' . $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false) . '" />' . '<span class="label"><label for="options_' . $_option->getId() . '_' . $count . '">' . $_value->getTitle(); $selectHtml .= !empty($priceStr) ? '<br>' : '    '; $selectHtml .= $priceStr . '</label></span>'; if ($_option->getIsRequire()) { $selectHtml .= '<script type="text/javascript">' . '$(\'options_' . $_option->getId() . '_' . $count . '\').advaiceContainer = \'options-' . $_option->getId() . '-container\';' . '$(\'options_' . $_option->getId() . '_' . $count . '\').callbackFunction = \'validateOptionsCallback\';' . '</script>'; } if ($checked == 'checked' && count($_option->getValues()) == 1) { $selectHtml .= '<br />ONE SIZE ONLY'; } $selectHtml .= '</li>'; } $selectHtml .= '</ul>'; return $selectHtml; } }
/** * Parse buyRequest into options values used by product * * @param Varien_Object $buyRequest * @return Varien_Object */ public function processBuyRequest(Varien_Object $buyRequest) { $options = new Varien_Object(); /* add product custom options data */ $customOptions = $buyRequest->getOptions(); if (is_array($customOptions)) { $options->setOptions(array_diff($buyRequest->getOptions(), array(''))); } /* 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; }
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); }