Ejemplo n.º 1
0
 /**
  * Apply options price
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $qty
  * @param double $finalPrice
  * @return double
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($optionIds = $product->getCustomOption('option_ids')) {
         $helper = Mage::helper('mageworx_customoptions');
         $basePrice = $finalPrice;
         $product->setActualPrice($basePrice);
         $finalPrice = 0;
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 $product->setCurrentPrice($finalPrice);
                 $option->setProduct($product);
                 if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT || $option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_TEXT) {
                     $quoteItemOption = $product->getCustomOption('option_' . $option->getId());
                     $group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
                     $finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $qty);
                 } else {
                     $price = $helper->getOptionPriceByQty($option, $qty);
                     if ($price != 0) {
                         $price = $price / $qty;
                     }
                     $finalPrice += $price;
                 }
             }
         }
         $product->setBaseCustomoptionsPrice($finalPrice);
         // for additional info
         if (!$helper->getProductAbsolutePrice($product) || $finalPrice == 0) {
             $finalPrice += $basePrice;
         }
     }
     if (method_exists($this, '_applyOptionsPriceFME')) {
         $finalPrice = $this->_applyOptionsPriceFME($product, $qty, $finalPrice);
     }
     return $finalPrice;
 }
Ejemplo n.º 2
0
 /**
  * @covers Mage_Catalog_Model_Product::addOption
  * @covers Mage_Catalog_Model_Product::getOptionById
  * @covers Mage_Catalog_Model_Product::getOptions
  */
 public function testOptionApi()
 {
     $this->assertEquals(array(), $this->_model->getOptions());
     $optionId = uniqid();
     $option = new Mage_Catalog_Model_Product_Option(array('key' => 'value'));
     $option->setId($optionId);
     $this->_model->addOption($option);
     $this->assertSame($option, $this->_model->getOptionById($optionId));
     $this->assertEquals(array($optionId => $option), $this->_model->getOptions());
 }
Ejemplo n.º 3
0
 /**
  * Apply options price
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $qty
  * @param float $finalPrice
  * @return float
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($optionIds = $product->getCustomOption('option_ids')) {
         $basePrice = $finalPrice;
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 $confItemOption = $product->getCustomOption('option_' . $option->getId());
                 $group = $option->groupFactory($option->getType())->setOption($option)->setConfigurationItemOption($confItemOption);
                 $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $basePrice);
             }
         }
     }
     return $finalPrice;
 }
Ejemplo n.º 4
0
 /**
  * Apply options price
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $qty
  * @param double $finalPrice
  * @return double
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($optionIds = $product->getCustomOption('option_ids')) {
         $basePrice = $finalPrice;
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 $optionValue = $product->getCustomOption('option_' . $option->getId())->getValue();
                 if ($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
                     foreach (split(',', $optionValue) as $value) {
                         $finalPrice += $this->_getPricingOptionValue(array('is_percent' => $option->getValueById($value)->getPriceType() == 'percent' ? true : false, 'pricing_value' => $option->getValueById($value)->getPrice()), $basePrice);
                     }
                 } elseif ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
                     $finalPrice += $this->_getPricingOptionValue(array('is_percent' => $option->getValueById($optionValue)->getPriceType() == 'percent' ? true : false, 'pricing_value' => $option->getValueById($optionValue)->getPrice()), $basePrice);
                 } else {
                     $finalPrice += $this->_getPricingOptionValue(array('is_percent' => $option->getPriceType() == 'percent' ? true : false, 'pricing_value' => $option->getPrice()), $basePrice);
                 }
             }
         }
     }
     return $finalPrice;
 }
Ejemplo n.º 5
0
 /**
  * Default action to get sku of product with option
  *
  * @param Mage_Catalog_Model_Product $product Product with Custom Options
  * @param string $sku Product SKU without option
  * @return string
  */
 public function getOptionSku($product, $sku = '')
 {
     $skuDelimiter = '-';
     if (empty($sku)) {
         $sku = $product->getData('sku');
     }
     if ($optionIds = $product->getCustomOption('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 $confItemOption = $product->getCustomOption(self::OPTION_PREFIX . $optionId);
                 $group = $option->groupFactory($option->getType())->setOption($option)->setListener(new Varien_Object());
                 if ($optionSku = $group->getOptionSku($confItemOption->getValue(), $skuDelimiter)) {
                     $sku .= $skuDelimiter . $optionSku;
                 }
                 if ($group->getListener()->getHasError()) {
                     $product->setHasError(true)->setMessage($group->getListener()->getMessage());
                 }
             }
         }
     }
     return $sku;
 }
Ejemplo n.º 6
0
 /**
  * Apply options price
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $qty
  * @param double $finalPrice
  * @return double
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($optionIds = $product->getCustomOption('option_ids')) {
         $basePrice = $finalPrice;
         $finalPrice = 0;
         $options = array();
         $qtyRelatedOption = null;
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 $options[] = $option;
                 if ($option->getOptionCode() == $this->_getQtyOptionCode()) {
                     $qtyRelatedOption = $option;
                 }
             }
         }
         foreach ($options as $option) {
             $optionQty = null;
             $quoteItemOptionInfoBuyRequest = unserialize($product->getCustomOption('info_buyRequest')->getValue());
             switch ($option->getType()) {
                 case 'checkbox':
                     if (isset($quoteItemOptionInfoBuyRequest['options'][$optionId])) {
                         $optionValues = array();
                         $optionQtyArr = array();
                         foreach ($option->getValues() as $key => $itemV) {
                             if (isset($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty'])) {
                                 $optionQty = intval($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty']);
                             } else {
                                 $optionQty = 1;
                             }
                             $optionQtyArr[$itemV->getOptionTypeId()] = $optionQty;
                         }
                         $optionQty = $optionQtyArr;
                         break;
                     }
                     break;
                 case 'drop_down':
                 case 'radio':
                     if (isset($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_qty'])) {
                         $optionQty = intval($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_qty']);
                     } else {
                         $optionQty = 1;
                     }
                 case 'multiple':
                     if (!isset($optionQty)) {
                         $optionQty = 1;
                     }
                     break;
                 case 'field':
                 case 'area':
                 case 'file':
                 case 'date':
                 case 'date_time':
                 case 'time':
                     break;
                 default:
                     //multiple
                     $optionQty = 1;
             }
             $option->setOptionQty($optionQty);
         }
         $customQty = 0;
         if ($qtyRelatedOption) {
             foreach ($qtyRelatedOption->getValues() as $_value) {
                 if (isset($quoteItemOptionInfoBuyRequest['options_' . $qtyRelatedOption->getOptionId() . '_' . $_value->getOptionTypeId() . '_qty'])) {
                     $customQty += intval($quoteItemOptionInfoBuyRequest['options_' . $qtyRelatedOption->getOptionId() . '_' . $_value->getOptionTypeId() . '_qty']);
                 }
             }
             if ($customQty) {
                 $basePrice = $product->getTierPrice($customQty);
             }
         }
         foreach ($options as $option) {
             switch ($option->getType()) {
                 case 'field':
                 case 'area':
                 case 'file':
                 case 'date':
                 case 'date_time':
                 case 'time':
                     $finalPrice += $this->_getCustomOptionsChargableOptionPrice($option->getPrice(), $option->getPriceType() == 'percent', $basePrice, $qty, $option->getCustomoptionsIsOnetime());
                     break;
                 case 'drop_down':
                 case 'radio':
                 case 'checkbox':
                     $quoteItemOption = $product->getCustomOption('option_' . $option->getId());
                     $group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
                     $optionPrice = $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $option != $qtyRelatedOption ? $customQty : $qty, $option->getOptionQty());
                     if ($option != $qtyRelatedOption && $customQty) {
                         $optionPrice *= $customQty;
                     }
                     $finalPrice += $optionPrice;
             }
         }
         if (!Mage::helper('customoptions')->isAbsolutePricesEnabled() || $finalPrice == 0) {
             $finalPrice += $customQty ? $customQty * $basePrice : $basePrice;
         }
     }
     return $finalPrice;
 }
Ejemplo n.º 7
0
 /**
  * Since it's a bad practice to overwrite core magento abstract classes via
  * copying the source in the local folder structure, this method contains the
  * same code found in Mage_Catalog_Model_Product_Type_Abstract.getSku; however,
  * it also includes logic to allow certain options to be disregarding from
  * sku concatination.
  *
  * NOTE: Since we're providing the same logic here that is in the base abstract
  * product type class, it is very important to check this logic during future
  * magento upgrades to ensure nothing gets broken.
  *
  * @param Mage_Catalog_Model_Product $product
  * @return string
  */
 public function getProductSku($product)
 {
     $excludeSkus = explode(',', Mage::getConfig()->getNode(self::XML_PATH_EXCLUDE_OPTIONS_SKU));
     $skuDelimiter = '-';
     $sku = $product->getData('sku');
     if ($optionIds = $product->getCustomOption('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 // pass over options with a title contained in the config
                 if (in_array($option->getTitle(), $excludeSkus)) {
                     continue;
                 }
                 $quoteItemOption = $product->getCustomOption('option_' . $optionId);
                 $group = $option->groupFactory($option->getType())->setOption($option)->setListener(new Varien_Object());
                 if ($optionSku = $group->getOptionSku($quoteItemOption->getValue(), $skuDelimiter)) {
                     $sku .= $skuDelimiter . $optionSku;
                 }
                 if ($group->getListener()->getHasError()) {
                     $product->setHasError(true)->setMessage($group->getListener()->getMessage());
                 }
             }
         }
     }
     return $sku;
 }
 /**
  * Apply options price
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $qty
  * @param double $finalPrice
  * @return double
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($optionIds = $product->getCustomOption('option_ids')) {
         $helper = Mage::helper('customoptions');
         $basePrice = $finalPrice;
         $finalPrice = 0;
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 $option->setProduct($product);
                 $optionQty = null;
                 $quoteItemOptionInfoBuyRequest = unserialize($product->getCustomOption('info_buyRequest')->getValue());
                 switch ($option->getType()) {
                     case 'checkbox':
                     case 'multiswatch':
                         if (isset($quoteItemOptionInfoBuyRequest['options'][$optionId])) {
                             $optionValues = array();
                             $optionQtyArr = array();
                             foreach ($option->getValues() as $key => $itemV) {
                                 if (isset($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty'])) {
                                     $optionQty = intval($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty']);
                                 } else {
                                     $optionQty = 1;
                                 }
                                 $optionQtyArr[$itemV->getOptionTypeId()] = $optionQty;
                             }
                             $optionQty = $optionQtyArr;
                             break;
                         }
                         break;
                     case 'drop_down':
                     case 'radio':
                     case 'swatch':
                         if (isset($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_qty'])) {
                             $optionQty = intval($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_qty']);
                         } else {
                             $optionQty = 1;
                         }
                     case 'multiple':
                         if (!isset($optionQty)) {
                             $optionQty = 1;
                         }
                         break;
                     case 'field':
                     case 'area':
                     case 'file':
                     case 'date':
                     case 'date_time':
                     case 'time':
                         break;
                 }
                 switch ($option->getType()) {
                     case 'field':
                     case 'area':
                     case 'file':
                     case 'date':
                     case 'date_time':
                     case 'time':
                         $price = $helper->getOptionPriceByQty($option, $qty, $product);
                         if ($price != 0) {
                             $price = $price / $qty;
                         }
                         $finalPrice += $price;
                         break;
                     default:
                         //multiple
                         $optionQty = 1;
                     case 'drop_down':
                     case 'radio':
                     case 'checkbox':
                     case 'swatch':
                     case 'multiswatch':
                         $quoteItemOption = $product->getCustomOption('option_' . $option->getId());
                         $group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
                         $finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $qty, $optionQty, $product);
                 }
             }
         }
         $product->setBaseCustomoptionsPrice($finalPrice);
         // for additional info
         if (!$helper->getProductAbsolutePrice($product) || $finalPrice == 0) {
             $finalPrice += $basePrice;
         }
     }
     if (method_exists($this, '_applyOptionsPriceFME')) {
         $finalPrice = $this->_applyOptionsPriceFME($product, $qty, $finalPrice);
     }
     return $finalPrice;
 }