Пример #1
0
 /**
  * Compare item
  *
  * @param   Mage_Sales_Model_Quote_Item $item
  * @return  bool
  */
 public function compare($item)
 {
     if ($item->getOptionByCode('chili_document_id')) {
         return false;
     }
     return parent::compare($item);
 }
 /**
  * Use our own method to get buyRequest
  * @param Mage_Sales_Model_Quote_Item $salesItem
  * @return Varien_Object
  *
  */
 public function getBuyRequest($salesItem, $option = false)
 {
     if ($option) {
         $option = $salesItem->getOptionByCode('info_buyRequest');
         $buyRequest = new Varien_Object($option && $option->getValue() ? unserialize($option->getValue()) : null);
         $buyRequest->setOriginalQty($buyRequest->getQty())->setQty($salesItem->getQty() * 1);
         return $buyRequest;
     }
     $option = $salesItem->getProductOptionByCode('info_buyRequest');
     if (!$option) {
         $option = array();
     }
     $buyRequest = new Varien_Object($option);
     $buyRequest->setQty($salesItem->getQtyOrdered() * 1);
     return $buyRequest;
 }
Пример #3
0
 /**
  * Returns the product id for a quote item.
  * Always try to find the "parent" product ID if the product is a child of
  * another product type. We do this because it is the parent product that
  * we tag on the product page, and the child does not always have it's own
  * product page. This is important because it is the tagged info on the
  * product page that is used to generate recommendations and email content.
  *
  * @param Mage_Sales_Model_Quote_Item $item the quote item model.
  *
  * @return int|string
  */
 public function getProductId($item)
 {
     $parentItem = $item->getOptionByCode('product_type');
     if (!is_null($parentItem)) {
         return $parentItem->getProductId();
     } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
         /** @var Mage_Catalog_Model_Product_Type_Configurable $model */
         $model = Mage::getModel('catalog/product_type_configurable');
         $parentIds = $model->getParentIdsByChild($item->getProductId());
         $attributes = $item->getBuyRequest()->getData('super_attribute');
         // If the product has a configurable parent, we assume we should tag
         // the parent. If there are many parent IDs, we are safer to tag the
         // products own ID.
         if (count($parentIds) === 1 && !empty($attributes)) {
             return $parentIds[0];
         }
     }
     return $item->getProductId();
 }
 /**
  * Get Custom Options of item
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 public function getCustomOptions(Mage_Sales_Model_Quote_Item $item)
 {
     $optionStr = '';
     $this->_moveToCustomerStorage = true;
     if ($optionIds = $item->getOptionByCode('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $item->getProduct()->getOptionById($optionId)) {
                 $optionValue = $item->getOptionByCode('option_' . $option->getId())->getValue();
                 $optionStr .= $option->getTitle() . ':';
                 $quoteItemOption = $item->getOptionByCode('option_' . $option->getId());
                 $group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
                 $optionStr .= $group->getEditableOptionValue($quoteItemOption->getValue());
                 $optionStr .= "\n";
             }
         }
     }
     return $optionStr;
 }
Пример #5
0
 /**
  * Compare item
  *
  * @param   Mage_Sales_Model_Quote_Item $item
  * @return  bool
  */
 public function compare($item)
 {
     if ($this->getProductId() != $item->getProductId()) {
         return false;
     }
     foreach ($this->getOptions() as $option) {
         if (in_array($option->getCode(), $this->_notRepresentOptions)) {
             continue;
         }
         if ($itemOption = $item->getOptionByCode($option->getCode())) {
             $itemOptionValue = $itemOption->getValue();
             $optionValue = $option->getValue();
             // dispose of some options params, that can cramp comparing of arrays
             if (is_string($itemOptionValue) && is_string($optionValue)) {
                 $_itemOptionValue = @unserialize($itemOptionValue);
                 $_optionValue = @unserialize($optionValue);
                 if (is_array($_itemOptionValue) && is_array($_optionValue)) {
                     $itemOptionValue = $_itemOptionValue;
                     $optionValue = $_optionValue;
                     // looks like it does not break bundle selection qty
                     unset($itemOptionValue['qty'], $itemOptionValue['uenc'], $optionValue['qty'], $optionValue['uenc']);
                 }
             }
             if ($itemOptionValue != $optionValue) {
                 return false;
             }
         } else {
             return false;
         }
     }
     return true;
 }
Пример #6
0
 /**
  * Prepare options array for info buy request
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 protected function _prepareOptionsForRequest($item)
 {
     $newInfoOptions = array();
     if ($optionIds = $item->getOptionByCode('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $option = $item->getProduct()->getOptionById($optionId);
             $optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
             $group = Mage::getSingleton('catalog/product_option')->groupFactory($option->getType())->setOption($option)->setQuoteItem($item);
             $newInfoOptions[$optionId] = $group->prepareOptionValueForRequest($optionValue);
         }
     }
     return $newInfoOptions;
 }
 /**
  * Compare item
  *
  * @param   Mage_Sales_Model_Quote_Item $item
  * @return  bool
  */
 public function compare($item)
 {
     if ($this->getProductId() != $item->getProductId()) {
         return false;
     }
     foreach ($this->getOptions() as $option) {
         if (in_array($option->getCode(), $this->_notRepresentOptions) && !$item->getProduct()->hasCustomOptions()) {
             continue;
         }
         if ($itemOption = $item->getOptionByCode($option->getCode())) {
             $itemOptionValue = $itemOption->getValue();
             $optionValue = $option->getValue();
             // dispose of some options params, that can cramp comparing of arrays
             if (is_string($itemOptionValue) && is_string($optionValue)) {
                 try {
                     /** @var Unserialize_Parser $parser */
                     $parser = Mage::helper('core/unserializeArray');
                     $_itemOptionValue = $parser->unserialize($itemOptionValue);
                     $_optionValue = $parser->unserialize($optionValue);
                     if (is_array($_itemOptionValue) && is_array($_optionValue)) {
                         $itemOptionValue = $_itemOptionValue;
                         $optionValue = $_optionValue;
                         // looks like it does not break bundle selection qty
                         unset($itemOptionValue['qty'], $itemOptionValue['uenc']);
                         unset($optionValue['qty'], $optionValue['uenc']);
                     }
                 } catch (Exception $e) {
                     Mage::logException($e);
                 }
             }
             if ($itemOptionValue != $optionValue) {
                 return false;
             }
         } else {
             return false;
         }
     }
     return true;
 }
Пример #8
0
 protected function getProductUrl(Mage_Sales_Model_Quote_Item $item)
 {
     if ($item->getRedirectUrl()) {
         return $item->getRedirectUrl();
     }
     $product = $item->getProduct();
     $option = $item->getOptionByCode('product_type');
     if ($option) {
         $product = $option->getProduct();
     }
     return $product->getUrlModel()->getUrl($product);
 }
Пример #9
0
 /**
  * Get Custom Options of item
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 public function getCustomOptions(Mage_Sales_Model_Quote_Item $item)
 {
     $optionStr = '';
     $this->_moveToCustomerStorage = true;
     if ($optionIds = $item->getOptionByCode('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $item->getProduct()->getOptionById($optionId)) {
                 $optionValue = $item->getOptionByCode('option_' . $option->getId())->getValue();
                 $optionStr .= $option->getTitle() . ':';
                 if ($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
                     foreach (explode(',', $optionValue) as $_value) {
                         $optionStr .= $option->getValueById($_value)->getTitle() . ', ';
                     }
                     $optionStr = Mage::helper('core/string')->substr($optionStr, 0, -2);
                 } elseif ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
                     $optionStr .= $option->getValueById($optionValue)->getTitle();
                 } else {
                     $optionStr .= $optionValue;
                 }
                 $optionStr .= "\n";
             }
         }
     }
     foreach ($item->getProduct()->getOptions() as $option) {
         if ($option->getIsRequire() && !$item->getOptionByCode('option_' . $option->getId())) {
             $optionStr .= $option->getTitle() . ':' . "\n";
         }
     }
     if ($additionalOptions = $item->getOptionByCode('additional_options')) {
         $this->_moveToCustomerStorage = false;
         foreach (unserialize($additionalOptions->getValue()) as $additionalOption) {
             $optionStr .= $additionalOption['label'] . ':' . $additionalOption['value'] . "\n";
         }
     }
     $optionStr = $this->helper('core/string')->substr($optionStr, 0, -1);
     return $optionStr;
 }
Пример #10
0
 /**
  * Prepare options array for info buy request
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 protected function _prepareOptionsForRequest($item)
 {
     $newInfoOptions = array();
     if ($optionIds = $item->getOptionByCode('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $optionType = $item->getProduct()->getOptionById($optionId)->getType();
             $optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
             if ($optionType == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $optionType == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
                 $optionValue = explode(',', $optionValue);
             }
             $newInfoOptions[$optionId] = $optionValue;
         }
     }
     return $newInfoOptions;
 }
Пример #11
0
 /**
  * @param Mage_Sales_Model_Quote_Item $quoteItem
  * @return bool|array
  */
 public function getSubscriptionOptionFromQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem)
 {
     $subscriptionOption = false;
     $additionalOptions = $quoteItem->getOptionByCode('additional_options');
     if ($quoteItem->getOptionByCode('additional_options')) {
         $additionalOptions = unserialize($additionalOptions->getValue());
         foreach ($additionalOptions as $option) {
             if ($option['code'] == 'adyen_subscription') {
                 $subscriptionOption = $option;
                 break;
             }
         }
     }
     return $subscriptionOption;
 }
Пример #12
0
 /**
  * Retrieve simple product from cart item option.
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return Mage_Catalog_Model_Product|null
  */
 public function getSimpleProductFromItemOptions(Mage_Sales_Model_Quote_Item $item)
 {
     $result = null;
     if ($item) {
         $o = $item->getOptionByCode('simple_product');
         if ($o && $o->getProductId()) {
             $result = Mage::getModel('catalog/product')->load($o->getProductId());
         }
     }
     return $result;
 }
 /**
  * Retrieves configuration options for grouped product
  *
  * @param  Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 protected function _getGroupedOptions($item)
 {
     $product = $item->getProduct();
     $options = array();
     /** @var $typeInstance Mage_Catalog_Model_Product_Type_Grouped */
     $typeInstance = $product->getTypeInstance(true);
     $associatedProducts = $typeInstance->getAssociatedProducts($product);
     if ($associatedProducts) {
         foreach ($associatedProducts as $associatedProduct) {
             /** @var $associatedProduct Mage_Catalog_Model_Product */
             $qty = $item->getOptionByCode('associated_product_' . $associatedProduct->getId());
             $option = array('label' => $associatedProduct->getName(), 'value' => $qty && $qty->getValue() ? $qty->getValue() : 0);
             $options[] = $option;
         }
     }
     return array_merge($options, $this->_getCustomOptions($item));
 }
Пример #14
0
 /**
  * Retrieve simple product id from quote item
  *
  * @param Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Quote_Address_Item $item
  *
  * @return int
  */
 protected function _retrieveProductIdFromQuoteItem($item)
 {
     $productId = $item->getProductId();
     if ($item->getOptionByCode('simple_product')) {
         $productId = $item->getOptionByCode('simple_product')->getProduct()->getId();
     }
     return $productId;
 }