Public Member Functions | |
getPrice ($product) | |
getFinalPrice ($qty=null, $product) | |
getChildFinalPrice ($product, $productQty, $childProduct, $childProductQty) | |
getTierPrice ($qty=null, $product) | |
getTierPriceCount ($product) | |
getFormatedTierPrice ($qty=null, $product) | |
getFormatedPrice ($product) | |
Static Public Member Functions | |
static | calculatePrice ($basePrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $rulePrice=false, $wId=null, $gId=null, $productId=null) |
static | calculateSpecialPrice ($finalPrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $store=null) |
Public Attributes | |
const | CACHE_TAG = 'PRODUCT_PRICE' |
Static Public Attributes | |
static | $attributeCache = array() |
Protected Member Functions | |
_applyTierPrice ($product, $qty, $finalPrice) | |
_getCustomerGroupId ($product) | |
_applySpecialPrice ($product, $finalPrice) | |
_applyOptionsPrice ($product, $qty, $finalPrice) |
Definition at line 34 of file Price.php.
_applyOptionsPrice | ( | $ | product, | |
$ | qty, | |||
$ | finalPrice | |||
) | [protected] |
Apply options price
Mage_Catalog_Model_Product | $product | |
int | $qty | |
double | $finalPrice |
Definition at line 245 of file Price.php.
00246 { 00247 if ($optionIds = $product->getCustomOption('option_ids')) { 00248 $basePrice = $finalPrice; 00249 foreach (explode(',', $optionIds->getValue()) as $optionId) { 00250 if ($option = $product->getOptionById($optionId)) { 00251 00252 $quoteItemOption = $product->getCustomOption('option_'.$option->getId()); 00253 $group = $option->groupFactory($option->getType()) 00254 ->setOption($option) 00255 ->setQuoteItemOption($quoteItemOption); 00256 00257 $finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice); 00258 } 00259 } 00260 } 00261 00262 return $finalPrice; 00263 }
_applySpecialPrice | ( | $ | product, | |
$ | finalPrice | |||
) | [protected] |
Apply special price for product if not return price that was before
Mage_Catalog_Model_Product | $product | |
double | $finalPrice |
Definition at line 187 of file Price.php.
00188 { 00189 return $this->calculateSpecialPrice($finalPrice, $product->getSpecialPrice(), $product->getSpecialFromDate(), $product->getSpecialToDate(), $product->getStore()); 00190 }
_applyTierPrice | ( | $ | product, | |
$ | qty, | |||
$ | finalPrice | |||
) | [protected] |
Apply tier price for product if not return price that was before
Mage_Catalog_Model_Product | $product | |
double | $qty | |
double | $finalPrice |
Reimplemented in Mage_Bundle_Model_Product_Price.
Definition at line 89 of file Price.php.
00090 { 00091 if (is_null($qty)) { 00092 return $finalPrice; 00093 } 00094 00095 $tierPrice = $product->getTierPrice($qty); 00096 if (is_numeric($tierPrice)) { 00097 $finalPrice = min($finalPrice, $tierPrice); 00098 } 00099 return $finalPrice; 00100 }
_getCustomerGroupId | ( | $ | product | ) | [protected] |
Definition at line 172 of file Price.php.
00173 { 00174 if ($product->getCustomerGroupId()) { 00175 return $product->getCustomerGroupId(); 00176 } 00177 return Mage::getSingleton('customer/session')->getCustomerGroupId(); 00178 }
static calculatePrice | ( | $ | basePrice, | |
$ | specialPrice, | |||
$ | specialPriceFrom, | |||
$ | specialPriceTo, | |||
$ | rulePrice = false , |
|||
$ | wId = null , |
|||
$ | gId = null , |
|||
$ | productId = null | |||
) | [static] |
Calculate product price based on special price data and price rules
float | $basePrice | |
float | $specialPrice | |
string | $specialPriceFrom | |
string | $specialPriceTo | |
float|null|false | $rulePrice | |
mixed | $wId | |
mixed | $gId | |
null|int | $productId |
Reimplemented in Mage_Bundle_Model_Product_Price.
Definition at line 278 of file Price.php.
00279 { 00280 Varien_Profiler::start('__PRODUCT_CALCULATE_PRICE__'); 00281 if ($wId instanceof Mage_Core_Model_Store) { 00282 $sId = $wId->getId(); 00283 $wId = $wId->getWebsiteId(); 00284 } else { 00285 $sId = Mage::app()->getWebsite($wId)->getDefaultGroup()->getDefaultStoreId(); 00286 } 00287 00288 $finalPrice = $basePrice; 00289 if ($gId instanceof Mage_Customer_Model_Group) { 00290 $gId = $gId->getId(); 00291 } 00292 00293 $finalPrice = self::calculateSpecialPrice($finalPrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $sId); 00294 00295 if ($rulePrice === false) { 00296 $storeTimestamp = Mage::app()->getLocale()->storeTimeStamp($sId); 00297 $rulePrice = Mage::getResourceModel('catalogrule/rule') 00298 ->getRulePrice($storeTimestamp, $wId, $gId, $productId); 00299 } 00300 00301 if ($rulePrice !== null && $rulePrice !== false) { 00302 $finalPrice = min($finalPrice, $rulePrice); 00303 } 00304 00305 $finalPrice = max($finalPrice, 0); 00306 Varien_Profiler::stop('__PRODUCT_CALCULATE_PRICE__'); 00307 return $finalPrice; 00308 }
static calculateSpecialPrice | ( | $ | finalPrice, | |
$ | specialPrice, | |||
$ | specialPriceFrom, | |||
$ | specialPriceTo, | |||
$ | store = null | |||
) | [static] |
Calculate and apply special price
float | $finalPrice | |
float | $specialPrice | |
string | $specialPriceFrom | |
string | $specialPriceTo | |
mixed | $store |
Reimplemented in Mage_Bundle_Model_Product_Price.
Definition at line 320 of file Price.php.
00321 { 00322 if (!is_null($specialPrice) && $specialPrice != false) { 00323 if (Mage::app()->getLocale()->IsStoreDateInInterval($store, $specialPriceFrom, $specialPriceTo)) { 00324 $finalPrice = min($finalPrice, $specialPrice); 00325 } 00326 } 00327 return $finalPrice; 00328 }
getChildFinalPrice | ( | $ | product, | |
$ | productQty, | |||
$ | childProduct, | |||
$ | childProductQty | |||
) |
Reimplemented in Mage_Bundle_Model_Product_Price.
Definition at line 76 of file Price.php.
00077 { 00078 return $this->getFinalPrice($childProductQty, $childProduct); 00079 }
getFinalPrice | ( | $ | qty = null , |
|
$ | product | |||
) |
Get product final price
double | $qty | |
Mage_Catalog_Model_Product | $product |
Reimplemented in Mage_Bundle_Model_Product_Price, Mage_Catalog_Model_Product_Type_Configurable_Price, and Mage_Downloadable_Model_Product_Price.
Definition at line 57 of file Price.php.
00058 { 00059 if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) { 00060 return $product->getCalculatedFinalPrice(); 00061 } 00062 00063 $finalPrice = $product->getPrice(); 00064 $finalPrice = $this->_applyTierPrice($product, $qty, $finalPrice); 00065 $finalPrice = $this->_applySpecialPrice($product, $finalPrice); 00066 $product->setFinalPrice($finalPrice); 00067 00068 Mage::dispatchEvent('catalog_product_get_final_price', array('product'=>$product)); 00069 00070 $finalPrice = $product->getData('final_price'); 00071 $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice); 00072 00073 return max(0, $finalPrice); 00074 }
getFormatedPrice | ( | $ | product | ) |
Get formated by currency product price
Mage_Catalog_Model_Product | $product |
Definition at line 232 of file Price.php.
00233 { 00234 return Mage::app()->getStore()->formatPrice($product->getFinalPrice()); 00235 }
getFormatedTierPrice | ( | $ | qty = null , |
|
$ | product | |||
) |
Get formated by currency tier price
double | $qty | |
Mage_Catalog_Model_Product | $product |
Definition at line 211 of file Price.php.
00212 { 00213 $price = $product->getTierPrice($qty); 00214 if (is_array($price)) { 00215 foreach ($price as $index => $value) { 00216 $price[$index]['formated_price'] = Mage::app()->getStore()->convertPrice($price[$index]['website_price'], true); 00217 } 00218 } 00219 else { 00220 $price = Mage::app()->getStore()->formatPrice($price); 00221 } 00222 00223 return $price; 00224 }
getPrice | ( | $ | product | ) |
Default action to get price of product
Reimplemented in Mage_Bundle_Model_Product_Price.
Definition at line 45 of file Price.php.
getTierPrice | ( | $ | qty = null , |
|
$ | product | |||
) |
Get product tier price by qty
double | $qty | |
Mage_Catalog_Model_Product | $product |
Reimplemented in Mage_Bundle_Model_Product_Price.
Definition at line 109 of file Price.php.
00110 { 00111 $allGroups = Mage_Customer_Model_Group::CUST_GROUP_ALL; 00112 $prices = $product->getData('tier_price'); 00113 00114 if (is_null($prices)) { 00115 if ($attribute = $product->getResource()->getAttribute('tier_price')) { 00116 $attribute->getBackend()->afterLoad($product); 00117 $prices = $product->getData('tier_price'); 00118 } 00119 } 00120 00121 if (is_null($prices) || !is_array($prices)) { 00122 if (!is_null($qty)) { 00123 return $product->getPrice(); 00124 } 00125 return array(array( 00126 'price' => $product->getPrice(), 00127 'website_price' => $product->getPrice(), 00128 'price_qty' => 1, 00129 'cust_group' => $allGroups, 00130 )); 00131 } 00132 00133 $custGroup = $this->_getCustomerGroupId($product); 00134 if ($qty) { 00135 $prevQty = 1; 00136 $prevPrice = $product->getPrice(); 00137 $prevGroup = $allGroups; 00138 00139 foreach ($prices as $price) { 00140 if ($price['cust_group']!=$custGroup && $price['cust_group']!=$allGroups) { 00141 // tier not for current customer group nor is for all groups 00142 continue; 00143 } 00144 if ($qty < $price['price_qty']) { 00145 // tier is higher than product qty 00146 continue; 00147 } 00148 if ($price['price_qty'] < $prevQty) { 00149 // higher tier qty already found 00150 continue; 00151 } 00152 if ($price['price_qty'] == $prevQty && $prevGroup != $allGroups && $price['cust_group'] == $allGroups) { 00153 // found tier qty is same as current tier qty but current tier group is ALL_GROUPS 00154 continue; 00155 } 00156 $prevPrice = $price['website_price']; 00157 $prevQty = $price['price_qty']; 00158 $prevGroup = $price['cust_group']; 00159 } 00160 return $prevPrice; 00161 } else { 00162 foreach ($prices as $i=>$price) { 00163 if ($price['cust_group']!=$custGroup && $price['cust_group']!=$allGroups) { 00164 unset($prices[$i]); 00165 } 00166 } 00167 } 00168 00169 return ($prices) ? $prices : array(); 00170 }
getTierPriceCount | ( | $ | product | ) |
Count how many tier prices we have for the product
Mage_Catalog_Model_Product | $product |
Definition at line 198 of file Price.php.