Ejemplo n.º 1
0
 /**
  * Apply gift card amount to price
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $qty
  * @param double $finalPrice
  * @return double
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($product->getCustomOption('card_amount') && $product->getPrice() == 0) {
         $amount = $product->getCustomOption('card_amount')->getValue();
         $finalPrice += $amount;
     }
     return $finalPrice;
 }
Ejemplo n.º 2
0
 /**
  * Apply gift card amount to price
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $qty
  * @param double $finalPrice
  * @return double
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($product->getCustomOption('card_amount') && $product->getPrice() == 0) {
         $amount = Mage::helper('directory')->currencyConvert($product->getCustomOption('card_amount')->getValue(), Mage::app()->getStore()->getCurrentCurrencyCode(), Mage::app()->getStore()->getBaseCurrency());
         //$amount = $product->getCustomOption('card_amount')->getValue();
         $finalPrice += $amount;
     }
     return $finalPrice;
 }
Ejemplo n.º 3
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.º 4
0
 /**
  * Check is virtual product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return bool
  */
 public function isVirtual($product = null)
 {
     if (!$product) {
         return false;
     }
     if ($product->getCustomOption('card_type')) {
         $type = $product->getCustomOption('card_type')->getValue();
     } else {
         $type = $product->getAttributeText('wts_gc_type');
     }
     if ($product && $type == 'offline') {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 5
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('customoptions');
         $basePrice = $finalPrice;
         $product->setActualPrice($basePrice);
         $finalPrice = 0;
         $post = $helper->getInfoBuyRequest($product);
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 $option->setProduct($product);
                 $optionQty = 1;
                 switch ($option->getType()) {
                     case 'checkbox':
                     case 'multiswatch':
                     case 'hidden':
                         if (isset($post['options'][$optionId])) {
                             $optionValues = array();
                             $optionQtyArr = array();
                             foreach ($option->getValues() as $key => $itemV) {
                                 if (isset($post['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty'])) {
                                     $optionQty = intval($post['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty']);
                                 }
                                 $optionQtyArr[$itemV->getOptionTypeId()] = $optionQty;
                             }
                             $optionQty = $optionQtyArr;
                         }
                         break;
                     case 'drop_down':
                     case 'radio':
                     case 'swatch':
                         if (isset($post['options_' . $optionId . '_qty'])) {
                             $optionQty = intval($post['options_' . $optionId . '_qty']);
                         }
                         break;
                 }
                 if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
                     $quoteItemOption = $product->getCustomOption('option_' . $option->getId());
                     $group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
                     $finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $qty, $optionQty, $product);
                 } else {
                     $price = $helper->getOptionPriceByQty($option, $qty, $product);
                     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.º 6
0
 /**
  * Get selection quantity
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $selectionId
  *
  * @return decimal
  */
 public function getSelectionQty($product, $selectionId)
 {
     $selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
     if ($selectionQty) {
         return $selectionQty->getValue();
     }
     return 0;
 }
Ejemplo n.º 7
0
 /**
  * Get product final price
  *
  * @param   double $qty
  * @param   Mage_Catalog_Model_Product $product
  * @return  double
  */
 public function getFinalPrice($qty = null, $product)
 {
     if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
         return $product->getCalculatedFinalPrice();
     }
     $finalPrice = $product->getPrice();
     if ($product->hasCustomOptions()) {
         $customOption = $product->getCustomOption('bundle_option_ids');
         $optionIds = unserialize($customOption->getValue());
         $customOption = $product->getCustomOption('bundle_selection_ids');
         $selectionIds = unserialize($customOption->getValue());
         $selections = $product->getTypeInstance()->getSelectionsByIds($selectionIds);
         foreach ($selections->getItems() as $selection) {
             if ($selection->isSalable()) {
                 $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
                 if ($selectionQty) {
                     $finalPrice = $finalPrice + $this->getSelectionPrice($product, $selection, $selectionQty->getValue());
                 }
             }
         }
     } else {
         if ($options = $this->getOptions($product)) {
             /* some strange thing
                foreach ($options as $option) {
                    $selectionCount = count($option->getSelections());
                    if ($selectionCount) {
                        foreach ($option->getSelections() as $selection) {
                            if ($selection->isSalable() && ($selection->getIsDefault() || ($option->getRequired() &&)) {
                                $finalPrice = $finalPrice + $this->getSelectionPrice($product, $selection);
                            }
                        }
                    }
                }
                */
         }
     }
     $finalPrice = $this->_applyTierPrice($product, $qty, $finalPrice);
     $finalPrice = $this->_applySpecialPrice($product, $finalPrice);
     $product->setFinalPrice($finalPrice);
     Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product));
     $finalPrice = $product->getData('final_price');
     $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
     return max(0, $product->getData('final_price'));
 }
 /**
  * Retrieve product final price
  *
  * @param integer $qty
  * @param Mage_Catalog_Model_Product $product
  * @return float
  */
 public function getFinalPrice($qty = null, $product)
 {
     $finalPrice = $product->getPrice();
     if ($product->hasCustomOptions()) {
         $customOption = $product->getCustomOption('giftcard_amount');
         if ($customOption) {
             $finalPrice += $customOption->getValue();
         }
     }
     $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
     $product->setData('final_price', $finalPrice);
     return max(0, $product->getData('final_price'));
 }
Ejemplo n.º 9
0
 /**
  * Get Total price  for Bundle items
  *
  * @param Mage_Catalog_Model_Product $product
  * @param null|float $qty
  * @return float
  */
 public function getTotalBundleItemsPrice($product, $qty = null)
 {
     $price = 0.0;
     if ($product->hasCustomOptions()) {
         $customOption = $product->getCustomOption('bundle_selection_ids');
         if ($customOption) {
             $selectionIds = unserialize($customOption->getValue());
             $selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product);
             $selections->addTierPriceData();
             Mage::dispatchEvent('prepare_catalog_product_collection_prices', array('collection' => $selections, 'store_id' => $product->getStoreId()));
             //I need to check the price base on an attribute added only to bundle type -- reservation price per product or general
             //for specific product it works on add to cart but not for general
             //here I use the parent or the children price base on
             foreach ($selections->getItems() as $selection) {
                 if ($selection->isSalable()) {
                     $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
                     if ($selectionQty) {
                         if ($selection->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE && $product->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_FORALL) {
                             $price = 0;
                             if (is_object($product->getCustomOption('info_buyRequest'))) {
                                 $source = unserialize($product->getCustomOption('info_buyRequest')->getValue());
                                 if (!isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION])) {
                                     continue;
                                 }
                                 $startingDate = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION];
                                 $endingDate = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION];
                                 $customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup();
                                 $price = $qty * ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product, $startingDate, $endingDate, $qty, $customerGroup);
                                 break;
                             }
                         } else {
                             if ($selection->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) {
                                 $Product = Mage::getModel('catalog/product')->load($selection->getProductId());
                                 if (is_object($product->getCustomOption('info_buyRequest'))) {
                                     $source = unserialize($product->getCustomOption('info_buyRequest')->getValue());
                                     if (isset($source['start_date']) && isset($source['end_date'])) {
                                         $customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup();
                                         $price = $price + $selectionQty->getValue() * ITwebexperts_Payperrentals_Helper_Price::calculatePrice($Product, $source['start_date'], $source['end_date'], $selectionQty, $customerGroup);
                                     }
                                 }
                             } else {
                                 $price += $this->getSelectionFinalTotalPrice($product, $selection, $qty, $selectionQty->getValue());
                             }
                         }
                     }
                 }
             }
         }
     }
     return $price;
 }
Ejemplo n.º 10
0
 /**
  * @covers Mage_Catalog_Model_Product::addCustomOption
  * @covers Mage_Catalog_Model_Product::setCustomOptions
  * @covers Mage_Catalog_Model_Product::getCustomOptions
  * @covers Mage_Catalog_Model_Product::getCustomOption
  * @covers Mage_Catalog_Model_Product::hasCustomOptions
  */
 public function testCustomOptionsApi()
 {
     $this->assertEquals(array(), $this->_model->getCustomOptions());
     $this->assertFalse($this->_model->hasCustomOptions());
     $this->_model->setId(99);
     $this->_model->addCustomOption('one', 'value1');
     $option = $this->_model->getCustomOption('one');
     $this->assertInstanceOf('Varien_Object', $option);
     $this->assertEquals($this->_model->getId(), $option->getProductId());
     $this->assertSame($option->getProduct(), $this->_model);
     $this->assertEquals('one', $option->getCode());
     $this->assertEquals('value1', $option->getValue());
     $this->assertEquals(array('one' => $option), $this->_model->getCustomOptions());
     $this->assertTrue($this->_model->hasCustomOptions());
     $this->_model->setCustomOptions(array('test'));
     $this->assertTrue(is_array($this->_model->getCustomOptions()));
 }
Ejemplo n.º 11
0
 /**
  * Get Total price  for Bundle items
  *
  * @param Mage_Catalog_Model_Product $product
  * @param null|float $qty
  * @return float
  */
 public function getTotalBundleItemsPrice($product, $qty = null)
 {
     $price = 0.0;
     if ($product->hasCustomOptions()) {
         $customOption = $product->getCustomOption('bundle_selection_ids');
         if ($customOption) {
             $selectionIds = unserialize($customOption->getValue());
             $selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product);
             $selections->addTierPriceData();
             Mage::dispatchEvent('prepare_catalog_product_collection_prices', array('collection' => $selections, 'store_id' => $product->getStoreId()));
             foreach ($selections->getItems() as $selection) {
                 if ($selection->isSalable()) {
                     $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
                     if ($selectionQty) {
                         $price += $this->getSelectionFinalTotalPrice($product, $selection, $qty, $selectionQty->getValue());
                     }
                 }
             }
         }
     }
     return $price;
 }
Ejemplo n.º 12
0
 /**
  * Retrieve product subscription, if product is a subscription, else false
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Adyen_Subscription_Model_Product_Subscription|false
  */
 public function getProductSubscription($product)
 {
     if (isset($product->getAttributes()['adyen_subscription_type'])) {
         if ($product->getData('adyen_subscription_type') != Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED) {
             $option = $product->getCustomOption('additional_options');
             if ($option) {
                 $additionalOptions = unserialize($option->getValue());
                 foreach ($additionalOptions as $additional) {
                     if ($additional['code'] == 'adyen_subscription') {
                         if ($additional['option_value'] != 'none') {
                             $subscription = Mage::getModel('adyen_subscription/product_subscription')->load($additional['option_value']);
                             if (!$subscription->getId()) {
                                 return false;
                             }
                             return $subscription;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 13
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;
 }
Ejemplo n.º 14
0
 /**
  * Get sku of product
  *
  * @param  Mage_Catalog_Model_Product $product
  * @return string
  */
 public function getSku($product)
 {
     $simpleOption = $product->getCustomOption('simple_product');
     if ($simpleOption) {
         $optionProduct = $simpleOption->getProduct();
         $simpleSku = null;
         if ($optionProduct) {
             $simpleSku = $simpleOption->getProduct()->getSku();
         }
         $sku = parent::getOptionSku($product, $simpleSku);
     } else {
         $sku = parent::getSku($product);
     }
     return $sku;
 }
Ejemplo n.º 15
0
 /**
  * Check is virtual product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return bool
  */
 public function isVirtual($product)
 {
     if ($product->hasCustomOptions()) {
         $customOption = $product->getCustomOption('bundle_selection_ids');
         $selectionIds = unserialize($customOption->getValue());
         $selections = $this->getSelectionsByIds($selectionIds, $product);
         $virtualCount = 0;
         foreach ($selections->getItems() as $selection) {
             if ($selection->isVirtual()) {
                 $virtualCount++;
             }
         }
         if ($virtualCount == count($selections)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 16
0
 /**
  * Import product recurring profile information
  * Returns false if it cannot be imported
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_Payment_Model_Recurring_Profile|false
  */
 public function importProduct(Mage_Catalog_Model_Product $product)
 {
     if ($product->isRecurring() && is_array($product->getRecurringProfile())) {
         // import recurring profile data
         $this->addData($product->getRecurringProfile());
         // automatically set product name if there is no schedule description
         if (!$this->hasScheduleDescription()) {
             $this->setScheduleDescription($product->getName());
         }
         // collect start datetime from the product options
         $options = $product->getCustomOption(self::PRODUCT_OPTIONS_KEY);
         if ($options) {
             $options = unserialize($options->getValue());
             if (is_array($options)) {
                 if (isset($options['start_datetime'])) {
                     $startDatetime = new Zend_Date($options['start_datetime'], Varien_Date::DATETIME_INTERNAL_FORMAT);
                     $this->setNearestStartDatetime($startDatetime);
                 }
             }
         }
         return $this->_filterValues();
     }
     return false;
 }
Ejemplo n.º 17
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.º 18
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.º 19
0
 /**
  * @param array $requestData
  * @magentoAppIsolation enabled
  * @magentoDataFixture Mage/Catalog/_files/two_products.php
  * two_products.php because there are products without options, and they don't intersect with product_simple.php
  * by ID
  */
 public function testPrepareForCart()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->load(10);
     // fixture
     $this->assertEmpty($product->getCustomOption('info_buyRequest'));
     $requestData = array('qty' => 5);
     $result = $this->_model->prepareForCart(new Varien_Object($requestData), $product);
     $this->assertArrayHasKey(0, $result);
     $this->assertSame($product, $result[0]);
     $buyRequest = $product->getCustomOption('info_buyRequest');
     $this->assertInstanceOf('Varien_Object', $buyRequest);
     $this->assertEquals($product->getId(), $buyRequest->getProductId());
     $this->assertSame($product, $buyRequest->getProduct());
     $this->assertEquals(serialize($requestData), $buyRequest->getValue());
 }
Ejemplo n.º 20
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.º 21
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;
 }
 /**
  * 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;
 }