Exemple #1
0
 /**
  * Return tier price, even it is less than base price
  *
  * @param   Mage_Catalog_Model_Product $product
  * @param   float $qty
  * @param   float $finalPrice
  * @return  float
  */
 protected function _applyTierPrice($product, $qty, $finalPrice)
 {
     if (is_null($qty)) {
         return $finalPrice;
     }
     $tierPrice = $product->getTierPrice($qty);
     if (is_numeric($tierPrice)) {
         $finalPrice = $tierPrice;
     }
     return $finalPrice;
 }
Exemple #2
0
 /**
  * Get formatted by currency tier price
  *
  * @param   float $qty
  * @param   Mage_Catalog_Model_Product $product
  * @return  array || float
  */
 public function getFormatedTierPrice($qty = null, $product)
 {
     $price = $product->getTierPrice($qty);
     if (is_array($price)) {
         foreach ($price as $index => $value) {
             $price[$index]['formated_price'] = Mage::app()->getStore()->convertPrice($price[$index]['website_price'], true);
         }
     } else {
         $price = Mage::app()->getStore()->formatPrice($price);
     }
     return $price;
 }
Exemple #3
0
 /**
  * Apply tier price for bundle
  *
  * @param   Mage_Catalog_Model_Product $product
  * @param   decimal $qty
  * @param   decimal $finalPrice
  * @return  decimal
  */
 protected function _applyTierPrice($product, $qty, $finalPrice)
 {
     if (is_null($qty)) {
         return $finalPrice;
     }
     $tierPrice = $product->getTierPrice($qty);
     if (is_numeric($tierPrice)) {
         $tierPrice = $finalPrice - $finalPrice * ($tierPrice / 100);
         $tierPrice = $this->_getApp()->getStore()->roundPrice($tierPrice);
         $finalPrice = min($finalPrice, $tierPrice);
     }
     return $finalPrice;
 }
Exemple #4
0
 /**
  * Get product final price
  *
  * @param double $qty
  * @param Mage_Catalog_Model_Product $product
  * @return double
  */
 public function getFinalPrice($qty = null, $product)
 {
     /**
      * Calculating final price for item of configurable product
      */
     if ($product->getSuperProduct() && $product->getSuperProduct()->isConfigurable()) {
         $finalPrice = $product->getSuperProduct()->getFinalPrice($qty);
         $attributes = $product->getSuperProduct()->getTypeInstance()->getConfigurableAttributes();
         foreach ($attributes as $attribute) {
             $value = $this->getValueByIndex($attribute->getPrices(), $product->getData($attribute->getProductAttribute()->getAttributeCode()));
             if ($value) {
                 if ($value['pricing_value'] != 0) {
                     $finalPrice += $product->getSuperProduct()->getPricingValue($value);
                 }
             }
         }
     } else {
         $finalPrice = $product->getPrice();
         $tierPrice = $product->getTierPrice($qty);
         if (is_numeric($tierPrice)) {
             $finalPrice = min($finalPrice, $tierPrice);
         }
         $specialPrice = $product->getSpecialPrice();
         if (is_numeric($specialPrice)) {
             $today = floor(time() / 86400) * 86400;
             #echo " TEST:"; echo date('Y-m-d H:i:s', $today).' , '.$product->getSpecialToDate();
             if ($product->getSpecialFromDate() && $today < strtotime($product->getSpecialFromDate())) {
                 #echo ' test1: '.$product->getSpecialFromDate();
             } elseif ($product->getSpecialToDate() && $today > strtotime($product->getSpecialToDate())) {
                 #echo ' test2: '.$product->getSpecialToDate();
             } else {
                 $finalPrice = min($finalPrice, $specialPrice);
             }
         }
     }
     $product->setFinalPrice($finalPrice);
     Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product));
     return $product->getData('final_price');
 }
Exemple #5
0
 /**
  * Edit tier prices
  * 
  * Uses a pipe-delimited string of qty:price to set tiers for the product row and appends.
  * Removes if REMOVE is present.
  * 
  * @todo Prevent duplicate tiers (by qty) being set
  * @internal Magento will save duplicate tiers; no enforcing unique tiers by qty, so we have to do this manually
  * @param Mage_Catalog_Model_Product $product Current product row
  * @param string $tier_prices_field Pipe-separated in the form of qty:price (e.g. 0=250=12.75|0=500=12.00)
  */
 private function _editTierPrices(&$product, $tier_prices_field = false, $store)
 {
     if ($tier_prices_field && !empty($tier_prices_field)) {
         if (trim($tier_prices_field) == 'REMOVE') {
             $product->setTierPrice(array());
         } else {
             if ($this->getBatchParams('append_tier_prices') == "true") {
                 //get current product tier prices
                 $existing_tps = $product->getTierPrice();
             } else {
                 $existing_tps = array();
             }
             $etp_lookup = array();
             //make a lookup array to prevent dup tiers by qty
             foreach ($existing_tps as $key => $etp) {
                 $etp_lookup[intval($etp['price_qty'])] = $key;
             }
             //parse incoming tier prices string
             $incoming_tierps = explode('|', $tier_prices_field);
             $tps_toAdd = array();
             $tierpricecount = 0;
             foreach ($incoming_tierps as $tier_str) {
                 //echo "t: " . $tier_str;
                 if (empty($tier_str)) {
                     continue;
                 }
                 $tmp = array();
                 $tmp = explode('=', $tier_str);
                 if ($tmp[1] == 0 && $tmp[2] == 0) {
                     continue;
                 }
                 //echo ('adding tier');
                 //print_r($tmp);
                 $tps_toAdd[$tierpricecount] = array('website_id' => 0, 'cust_group' => $tmp[0], 'price_qty' => $tmp[1], 'price' => $tmp[2], 'delete' => '');
                 //drop any existing tier values by qty
                 if (isset($etp_lookup[intval($tmp[1])])) {
                     unset($existing_tps[$etp_lookup[intval($tmp[1])]]);
                 }
                 $tierpricecount++;
             }
             //combine array
             $tps_toAdd = array_merge($existing_tps, $tps_toAdd);
             //print_r($tps_toAdd);
             //save it
             $product->setTierPrice($tps_toAdd);
         }
     }
 }
Exemple #6
0
 /**
  * Apply tier price for bundle
  *
  * @param   Mage_Catalog_Model_Product $product
  * @param   decimal $qty
  * @param   decimal $finalPrice
  * @return  decimal
  */
 protected function _applyTierPrice($product, $qty, $finalPrice)
 {
     if (is_null($qty)) {
         return $finalPrice;
     }
     $tierPrice = $product->getTierPrice($qty);
     if (is_numeric($tierPrice)) {
         $tierPrice = $finalPrice - $finalPrice * $tierPrice / 100;
         $finalPrice = min($finalPrice, $tierPrice);
     }
     return $finalPrice;
 }
Exemple #7
0
 /**
  * See detailed tests at Mage_Catalog_Model_Product_Type*_PriceTest
  */
 public function testGetTierPrice()
 {
     $this->assertEquals(array(), $this->_model->getTierPrice());
 }
Exemple #8
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;
 }