Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Item Sku Qty Subtotal
- Item one ZLOB-SBLS-XL 1 $39.99
- Item Two ZTWS-SBLS-XL 1 $29.99
- public function getFinalPrice($qty=null, $product)
- {
- //Start edit
- $selectedAttributes = array();
- if ($product->getCustomOption('attributes')) {
- $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
- }
- //End edit
- if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product);
- if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
- return $product->getCalculatedFinalPrice();
- }
- $basePrice = $this->getBasePrice($product, $qty);
- $finalPrice = $basePrice;
- $product->setFinalPrice($finalPrice);
- Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
- $finalPrice = $product->getData('final_price');
- $finalPrice += $this->getTotalConfigurableItemsPrice($product, $finalPrice);
- $finalPrice += $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice;
- $finalPrice = max(0, $finalPrice);
- $product->setFinalPrice($finalPrice);
- return $finalPrice;
- }
- public function getSimpleProductPrice($qty=null, $product)
- {
- $cfgId = $product->getId();
- $product->getTypeInstance(true)
- ->setStoreFilter($product->getStore(), $product);
- $attributes = $product->getTypeInstance(true)
- ->getConfigurableAttributes($product);
- $selectedAttributes = array();
- if ($product->getCustomOption('attributes')) {
- $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
- }
- $db = Mage::getSingleton('core/resource')->getConnection('core_read');
- $dbMeta = Mage::getSingleton('core/resource');
- $sql = <<<SQL
- SELECT main_table.entity_id FROM {$dbMeta->getTableName('catalog/product')} `main_table` INNER JOIN
- {$dbMeta->getTableName('catalog/product_super_link')} `sl` ON sl.parent_id = {$cfgId}
- SQL;
- foreach($selectedAttributes as $attributeId => $optionId) {
- $alias = "a{$attributeId}";
- $sql .= ' INNER JOIN ' . $dbMeta->getTableName('catalog/product') . "_int" . " $alias ON $alias.entity_id = main_table.entity_id AND $alias.attribute_id = $attributeId AND $alias.value = $optionId AND $alias.entity_id = sl.product_id";
- }
- $id = $db->fetchOne($sql);
- return Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
- }
- Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
- $fp = Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
- return $product->setFinalPrice($fp);
- class YourFolderinLOCAL_YourModulename_Model_Observer
- {
- public function simpleProductPrice(Varien_Event_Observer $observer) {
- $event = $observer->getEvent();
- $product = $event->getProduct();
- $qty = $event->getQty();
- //Mage::log($observer, null, 'confPricing.log');
- // process percentage discounts only for simple products
- $selectedAttributes = array();
- if ($product->getCustomOption('attributes')) {
- Mage::log('yes-----', null, 'confPricing.log');
- $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
- }
- if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product);
- }
- public function getSimpleProductPrice($qty=null, $product)
- {
- $cfgId = $product->getId();
- $product->getTypeInstance(true)
- ->setStoreFilter($product->getStore(), $product);
- $attributes = $product->getTypeInstance(true)
- ->getConfigurableAttributes($product);
- $selectedAttributes = array();
- if ($product->getCustomOption('attributes')) {
- $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
- }
- $db = Mage::getSingleton('core/resource')->getConnection('core_read');
- $dbMeta = Mage::getSingleton('core/resource');
- $sql = <<<SQL
- SELECT main_table.entity_id FROM {$dbMeta->getTableName('catalog/product')} `main_table` INNER JOIN
- {$dbMeta->getTableName('catalog/product_super_link')} `sl` ON sl.parent_id = {$cfgId}
- SQL;
- foreach($selectedAttributes as $attributeId => $optionId) {
- $alias = "a{$attributeId}";
- $sql .= ' INNER JOIN ' . $dbMeta->getTableName('catalog/product') . "_int" . " $alias ON $alias.entity_id = main_table.entity_id AND $alias.attribute_id = $attributeId AND $alias.value = $optionId AND $alias.entity_id = sl.product_id";
- }
- $id = $db->fetchOne($sql);
- //Mage::log(Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty), null, 'confPricing.log');
- //return
- $fp = Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
- return $product->setFinalPrice($fp);
- }
- }
- <?xml version="1.0"?>
- <config>
- <modules>
- <YourFolderinLOCAL_YourModulename>
- <version>0.0.1</version>
- </YourFolderinLOCAL_YourModulename>
- </modules>
- <global>
- <models>
- <YourFolderinLOCALYourModulename><!-- Al lovwercase in my case -->
- <class>Your_Model</class><!-- not needed in my case -->
- </YourFolderinLOCALYourModulename>
- </models>
- </global>
- <frontend>
- <events>
- <catalog_product_get_final_price>
- <observers>
- <YourFolderinLOCAL_YourModulename_model_observer>
- <type>singleton</type>
- <class> YourFolderinLOCAL_YourModulename_Model_Observer</class>
- <method>simpleProductPrice</method>
- </YourFolderinLOCAL_YourModulenameg_model_observer>
- </observers>
- </catalog_product_get_final_price>
- </events>
- </frontend>
- </config>
- sales_quote_item_set_product
- public function loadQuote(Varien_Event_Observer $observer)
- {
- $event = $observer->getEvent();
- $quote_item = $event->getQuoteItem();
- $storeId = $quote_item->getStoreId();
- $item = $observer->getQuoteItem();
- $product = $observer->getProduct();
- $sku = $product->getSku();
- $productDetails = Mage::getModel('catalog/product')
- ->setStoreId($storeId)
- ->loadByAttribute('sku',$sku);
- $price = $productDetails->getPrice();
- $sprice = $productDetails->getFinalPrice();
- $item->setOriginalCustomPrice($sprice);
- $item->setOriginalPrice($price);
- }
- <events>
- <catalog_product_get_final_price>
- <observers>
- <Setblue_Banner_Model_Observer>
- <type>singleton</type>
- <class>Setblue_Banner_Model_Observer</class>
- <method>getFinalPrice</method>
- </Setblue_Banner_Model_Observer>
- </observers>
- </catalog_product_get_final_price>
- </events>
- <?php
- class Setblue_Banner_Model_Observer
- {
- public function getFinalPrice(Varien_Event_Observer $observer) {
- $event = $observer->getEvent();
- $product = $event->getProduct();
- $qty = $event->getQty();
- $selectedAttributes = array();
- if ($product->getCustomOption('attributes')) {
- Mage::log('yes-----', null, 'confPricing.log');
- $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
- }
- if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product);
- }
- public function getSimpleProductPrice($qty=null, $product)
- {
- $cfgId = $product->getId();
- $product->getTypeInstance(true)
- ->setStoreFilter($product->getStore(), $product);
- $attributes = $product->getTypeInstance(true)
- ->getConfigurableAttributes($product);
- $selectedAttributes = array();
- if ($product->getCustomOption('attributes')) {
- $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
- }
- $db = Mage::getSingleton('core/resource')->getConnection('core_read');
- $dbMeta = Mage::getSingleton('core/resource');
- $sql = <<<SQL
- SELECT main_table.entity_id FROM {$dbMeta->getTableName('catalog/product')} `main_table` INNER JOIN
- {$dbMeta->getTableName('catalog/product_super_link')} `sl` ON sl.parent_id = {$cfgId}
- SQL;
- foreach($selectedAttributes as $attributeId => $optionId) {
- $alias = "a{$attributeId}";
- $sql .= ' INNER JOIN ' . $dbMeta->getTableName('catalog/product') . "_int" . " $alias ON $alias.entity_id = main_table.entity_id AND $alias.attribute_id = $attributeId AND $alias.value = $optionId AND $alias.entity_id = sl.product_id";
- }
- $id = $db->fetchOne($sql);
- //Mage::log(Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty), null, 'confPricing.log');
- //return
- $fp = Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
- return $product->setFinalPrice($fp);
- }
- }
- ?>
- <ul class="productIds" style="display:none;">
- <?php
- $configurableProduct = Mage::getModel('catalog/product')->load($_product->getId());
- $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$configurableProduct);
- foreach($childProducts as $child) {
- $_productObj = Mage::getModel('catalog/product')->load($child->getId());
- ?>
- <li id='simple_<?php echo $child->getId(); ?>'><?php echo Mage::helper('core')->currency($_productObj->getFinalPrice()); ?></li>
- <?php
- }
- ?>
- </ul>
- reloadPrice: function(){
- if (this.config.disablePriceReload) {
- return;
- }
- var price = 0;
- var oldPrice = 0;
- for(var i=this.settings.length-1;i>=0;i--){
- var selected = this.settings[i].options[this.settings[i].selectedIndex];
- if(selected.config){
- price += parseFloat(selected.config.price);
- oldPrice += parseFloat(selected.config.oldPrice);
- }
- }
- /* Edit Code By Chandresh Rana*/
- //optionsPrice.changePrice('config', {'price': price, 'oldPrice': oldPrice});
- optionsPrice.reload();
- var existingProducts = new Object();
- for(var i=this.settings.length-1;i>=0;i--)
- {
- var selected = this.settings[i].options[this.settings[i].selectedIndex];
- if(selected.config)
- {
- for(var iproducts=0;iproducts<selected.config.products.length;iproducts++)
- {
- var usedAsKey = selected.config.products[iproducts]+"";
- if(existingProducts[usedAsKey]==undefined)
- {
- existingProducts[usedAsKey]=1;
- }
- else
- {
- existingProducts[usedAsKey]=existingProducts[usedAsKey]+1;
- }
- }
- }
- }
- for (var keyValue in existingProducts)
- {
- for ( var keyValueInner in existingProducts)
- {
- if(Number(existingProducts[keyValueInner])<Number(existingProducts[keyValue]))
- {
- delete existingProducts[keyValueInner];
- }
- }
- }
- var sizeOfExistingProducts=0;
- var currentSimpleProductId = "";
- for ( var keyValue in existingProducts)
- {
- currentSimpleProductId = keyValue;
- sizeOfExistingProducts=sizeOfExistingProducts+1
- }
- if(sizeOfExistingProducts==1)
- {
- if($('product-price-'+this.config.productId)){
- $('product-price-'+this.config.productId).innerHTML = jQuery("#simple_"+currentSimpleProductId).html();
- }
- }
- // End Code By Chandresh Rana
- return price;
- if($('product-price-'+this.config.productId)){
- $('product-price-'+this.config.productId).innerHTML = price;
- }
- this.reloadOldPrice();
- },
Add Comment
Please, Sign In to add comment