Guest User

Untitled

a guest
May 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.97 KB | None | 0 0
  1. Item Sku Qty Subtotal
  2. Item one ZLOB-SBLS-XL 1 $39.99
  3. Item Two ZTWS-SBLS-XL 1 $29.99
  4.  
  5. public function getFinalPrice($qty=null, $product)
  6. {
  7. //Start edit
  8. $selectedAttributes = array();
  9. if ($product->getCustomOption('attributes')) {
  10. $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
  11. }
  12. //End edit
  13. if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product);
  14.  
  15. if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
  16. return $product->getCalculatedFinalPrice();
  17. }
  18.  
  19. $basePrice = $this->getBasePrice($product, $qty);
  20. $finalPrice = $basePrice;
  21. $product->setFinalPrice($finalPrice);
  22. Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
  23. $finalPrice = $product->getData('final_price');
  24.  
  25. $finalPrice += $this->getTotalConfigurableItemsPrice($product, $finalPrice);
  26. $finalPrice += $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice;
  27. $finalPrice = max(0, $finalPrice);
  28.  
  29. $product->setFinalPrice($finalPrice);
  30. return $finalPrice;
  31. }
  32.  
  33. public function getSimpleProductPrice($qty=null, $product)
  34. {
  35. $cfgId = $product->getId();
  36. $product->getTypeInstance(true)
  37. ->setStoreFilter($product->getStore(), $product);
  38. $attributes = $product->getTypeInstance(true)
  39. ->getConfigurableAttributes($product);
  40. $selectedAttributes = array();
  41. if ($product->getCustomOption('attributes')) {
  42. $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
  43. }
  44. $db = Mage::getSingleton('core/resource')->getConnection('core_read');
  45. $dbMeta = Mage::getSingleton('core/resource');
  46. $sql = <<<SQL
  47. SELECT main_table.entity_id FROM {$dbMeta->getTableName('catalog/product')} `main_table` INNER JOIN
  48. {$dbMeta->getTableName('catalog/product_super_link')} `sl` ON sl.parent_id = {$cfgId}
  49. SQL;
  50. foreach($selectedAttributes as $attributeId => $optionId) {
  51. $alias = "a{$attributeId}";
  52. $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";
  53. }
  54. $id = $db->fetchOne($sql);
  55. return Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
  56. }
  57.  
  58. Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
  59.  
  60. $fp = Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
  61. return $product->setFinalPrice($fp);
  62.  
  63. class YourFolderinLOCAL_YourModulename_Model_Observer
  64. {
  65.  
  66. public function simpleProductPrice(Varien_Event_Observer $observer) {
  67. $event = $observer->getEvent();
  68. $product = $event->getProduct();
  69. $qty = $event->getQty();
  70. //Mage::log($observer, null, 'confPricing.log');
  71. // process percentage discounts only for simple products
  72.  
  73.  
  74. $selectedAttributes = array();
  75. if ($product->getCustomOption('attributes')) {
  76. Mage::log('yes-----', null, 'confPricing.log');
  77. $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
  78. }
  79.  
  80. if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product);
  81.  
  82.  
  83.  
  84. }
  85.  
  86.  
  87. public function getSimpleProductPrice($qty=null, $product)
  88. {
  89.  
  90. $cfgId = $product->getId();
  91. $product->getTypeInstance(true)
  92. ->setStoreFilter($product->getStore(), $product);
  93. $attributes = $product->getTypeInstance(true)
  94. ->getConfigurableAttributes($product);
  95. $selectedAttributes = array();
  96. if ($product->getCustomOption('attributes')) {
  97. $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
  98. }
  99. $db = Mage::getSingleton('core/resource')->getConnection('core_read');
  100. $dbMeta = Mage::getSingleton('core/resource');
  101. $sql = <<<SQL
  102. SELECT main_table.entity_id FROM {$dbMeta->getTableName('catalog/product')} `main_table` INNER JOIN
  103. {$dbMeta->getTableName('catalog/product_super_link')} `sl` ON sl.parent_id = {$cfgId}
  104. SQL;
  105. foreach($selectedAttributes as $attributeId => $optionId) {
  106. $alias = "a{$attributeId}";
  107. $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";
  108. }
  109. $id = $db->fetchOne($sql);
  110. //Mage::log(Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty), null, 'confPricing.log');
  111. //return
  112. $fp = Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
  113. return $product->setFinalPrice($fp);
  114. }
  115.  
  116.  
  117. }
  118.  
  119. <?xml version="1.0"?>
  120. <config>
  121. <modules>
  122. <YourFolderinLOCAL_YourModulename>
  123. <version>0.0.1</version>
  124. </YourFolderinLOCAL_YourModulename>
  125. </modules>
  126. <global>
  127. <models>
  128. <YourFolderinLOCALYourModulename><!-- Al lovwercase in my case -->
  129. <class>Your_Model</class><!-- not needed in my case -->
  130. </YourFolderinLOCALYourModulename>
  131. </models>
  132.  
  133. </global>
  134. <frontend>
  135. <events>
  136. <catalog_product_get_final_price>
  137. <observers>
  138. <YourFolderinLOCAL_YourModulename_model_observer>
  139. <type>singleton</type>
  140. <class> YourFolderinLOCAL_YourModulename_Model_Observer</class>
  141. <method>simpleProductPrice</method>
  142. </YourFolderinLOCAL_YourModulenameg_model_observer>
  143. </observers>
  144. </catalog_product_get_final_price>
  145.  
  146. </events>
  147. </frontend>
  148. </config>
  149.  
  150. sales_quote_item_set_product
  151.  
  152. public function loadQuote(Varien_Event_Observer $observer)
  153. {
  154.  
  155. $event = $observer->getEvent();
  156. $quote_item = $event->getQuoteItem();
  157. $storeId = $quote_item->getStoreId();
  158. $item = $observer->getQuoteItem();
  159. $product = $observer->getProduct();
  160. $sku = $product->getSku();
  161. $productDetails = Mage::getModel('catalog/product')
  162. ->setStoreId($storeId)
  163. ->loadByAttribute('sku',$sku);
  164.  
  165. $price = $productDetails->getPrice();
  166. $sprice = $productDetails->getFinalPrice();
  167.  
  168. $item->setOriginalCustomPrice($sprice);
  169. $item->setOriginalPrice($price);
  170.  
  171. }
  172.  
  173. <events>
  174. <catalog_product_get_final_price>
  175. <observers>
  176. <Setblue_Banner_Model_Observer>
  177. <type>singleton</type>
  178. <class>Setblue_Banner_Model_Observer</class>
  179. <method>getFinalPrice</method>
  180. </Setblue_Banner_Model_Observer>
  181. </observers>
  182. </catalog_product_get_final_price>
  183. </events>
  184.  
  185. <?php
  186. class Setblue_Banner_Model_Observer
  187. {
  188.  
  189. public function getFinalPrice(Varien_Event_Observer $observer) {
  190.  
  191. $event = $observer->getEvent();
  192. $product = $event->getProduct();
  193. $qty = $event->getQty();
  194.  
  195. $selectedAttributes = array();
  196. if ($product->getCustomOption('attributes')) {
  197. Mage::log('yes-----', null, 'confPricing.log');
  198. $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
  199. }
  200.  
  201. if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product);
  202.  
  203. }
  204.  
  205. public function getSimpleProductPrice($qty=null, $product)
  206. {
  207.  
  208. $cfgId = $product->getId();
  209. $product->getTypeInstance(true)
  210. ->setStoreFilter($product->getStore(), $product);
  211. $attributes = $product->getTypeInstance(true)
  212. ->getConfigurableAttributes($product);
  213. $selectedAttributes = array();
  214. if ($product->getCustomOption('attributes')) {
  215. $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
  216. }
  217. $db = Mage::getSingleton('core/resource')->getConnection('core_read');
  218. $dbMeta = Mage::getSingleton('core/resource');
  219. $sql = <<<SQL
  220. SELECT main_table.entity_id FROM {$dbMeta->getTableName('catalog/product')} `main_table` INNER JOIN
  221. {$dbMeta->getTableName('catalog/product_super_link')} `sl` ON sl.parent_id = {$cfgId}
  222. SQL;
  223. foreach($selectedAttributes as $attributeId => $optionId) {
  224. $alias = "a{$attributeId}";
  225. $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";
  226. }
  227. $id = $db->fetchOne($sql);
  228. //Mage::log(Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty), null, 'confPricing.log');
  229. //return
  230. $fp = Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
  231. return $product->setFinalPrice($fp);
  232. }
  233.  
  234. }
  235.  
  236. ?>
  237.  
  238. <ul class="productIds" style="display:none;">
  239. <?php
  240. $configurableProduct = Mage::getModel('catalog/product')->load($_product->getId());
  241. $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$configurableProduct);
  242. foreach($childProducts as $child) {
  243. $_productObj = Mage::getModel('catalog/product')->load($child->getId());
  244. ?>
  245. <li id='simple_<?php echo $child->getId(); ?>'><?php echo Mage::helper('core')->currency($_productObj->getFinalPrice()); ?></li>
  246. <?php
  247. }
  248. ?>
  249. </ul>
  250.  
  251. reloadPrice: function(){
  252. if (this.config.disablePriceReload) {
  253. return;
  254. }
  255. var price = 0;
  256. var oldPrice = 0;
  257. for(var i=this.settings.length-1;i>=0;i--){
  258. var selected = this.settings[i].options[this.settings[i].selectedIndex];
  259. if(selected.config){
  260. price += parseFloat(selected.config.price);
  261. oldPrice += parseFloat(selected.config.oldPrice);
  262. }
  263. }
  264.  
  265. /* Edit Code By Chandresh Rana*/
  266.  
  267. //optionsPrice.changePrice('config', {'price': price, 'oldPrice': oldPrice});
  268. optionsPrice.reload();
  269.  
  270. var existingProducts = new Object();
  271. for(var i=this.settings.length-1;i>=0;i--)
  272. {
  273. var selected = this.settings[i].options[this.settings[i].selectedIndex];
  274. if(selected.config)
  275. {
  276. for(var iproducts=0;iproducts<selected.config.products.length;iproducts++)
  277. {
  278. var usedAsKey = selected.config.products[iproducts]+"";
  279. if(existingProducts[usedAsKey]==undefined)
  280. {
  281. existingProducts[usedAsKey]=1;
  282. }
  283. else
  284. {
  285. existingProducts[usedAsKey]=existingProducts[usedAsKey]+1;
  286. }
  287. }
  288. }
  289. }
  290.  
  291. for (var keyValue in existingProducts)
  292. {
  293. for ( var keyValueInner in existingProducts)
  294. {
  295. if(Number(existingProducts[keyValueInner])<Number(existingProducts[keyValue]))
  296. {
  297. delete existingProducts[keyValueInner];
  298. }
  299. }
  300. }
  301.  
  302. var sizeOfExistingProducts=0;
  303. var currentSimpleProductId = "";
  304. for ( var keyValue in existingProducts)
  305. {
  306. currentSimpleProductId = keyValue;
  307. sizeOfExistingProducts=sizeOfExistingProducts+1
  308. }
  309.  
  310. if(sizeOfExistingProducts==1)
  311. {
  312. if($('product-price-'+this.config.productId)){
  313. $('product-price-'+this.config.productId).innerHTML = jQuery("#simple_"+currentSimpleProductId).html();
  314. }
  315.  
  316. }
  317. // End Code By Chandresh Rana
  318.  
  319. return price;
  320.  
  321. if($('product-price-'+this.config.productId)){
  322. $('product-price-'+this.config.productId).innerHTML = price;
  323. }
  324. this.reloadOldPrice();
  325. },
Add Comment
Please, Sign In to add comment