{"id":13031,"date":"2017-05-02T17:35:38","date_gmt":"2017-05-02T14:35:38","guid":{"rendered":"https:\/\/belvg.com\/blog\/?p=13031"},"modified":"2025-02-11T08:20:57","modified_gmt":"2025-02-11T06:20:57","slug":"how-to-show-discount-savings-in-magento","status":"publish","type":"post","link":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html","title":{"rendered":"How To Show Discount Savings in Magento"},"content":{"rendered":"<p><b>First off, let&#8217;s nail down the task that we need to complete.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">We have to create a module that should output the following text line on product and catalog pages: <\/span><b>&#8220;You have saved XXX%&#8221;<\/b><span style=\"font-weight: 400;\"> (where XXX is a whole number defining the discount rate), provided that the product is set to a special price (a discount price).<\/span><!--more--><span style=\"font-weight: 400;\">&#160;To complete this sort of task in our module we are going to use events.<\/span><span style=\"font-weight: 400;\"> But b<\/span><span style=\"font-weight: 400;\">efore we continue, let&#8217;s turn our attention to 2 additional methods that let you redefine the default Magento behavior, yet which are highly undesirable to use.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The <strong>first method<\/strong> is based on scopes (<\/span><span style=\"font-weight: 400;\">(<\/span><i><span style=\"font-weight: 400;\">app\/code\/local, app\/code\/community, app\/code\/core<\/span><\/i><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\">) and peculiarities of autoloader.&#160;<\/span><span style=\"font-weight: 400;\">Each scope has a definite visibility scope which allows redefining classes by simple file copying and then changing the logic of the class in accordance with your own needs. Besides, the given scopes are loaded in a specific order within the <\/span><em><span style=\"font-weight: 400;\">app\/Mage.php<\/span><\/em><span style=\"font-weight: 400;\"> file by modifying the <\/span><em>php include_path <\/em><span style=\"font-weight: 400;\">directive:<\/span><\/p>\n<pre class=\"lang:php decode:true \">$paths = array();\r\n$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';\r\n$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';\r\n$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';\r\n$paths[] = BP . DS . 'lib';\r\n$appPath = implode(PS, $paths);\r\nset_include_path($appPath . PS . Mage::registry('original_include_path'));\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">If we had decided to use this method for our task, we would need to copy the <\/span><i><span style=\"font-weight: 400;\">app\/code\/core.Mage\/Catalog\/Block\/Product\/Price.php file into app\/code\/local\/Mage\/Catalog\/Block\/Product\/Price.php <\/span><\/i><span style=\"font-weight: 400;\">and then add the required functionality.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The<strong> second method<\/strong> lets us modify the logic of the initial class but without direct copying.&#160;<\/span><span style=\"font-weight: 400;\">To understand how this works, let&#8217;s check the rewrite directive of the module&#8217;s config file.&#160;<\/span><span style=\"font-weight: 400;\">This directive is used to redefine the performance of models, blocks and helpers.&#160;<\/span><span style=\"font-weight: 400;\">In our case, we would have to redefine the performance of the class in the <\/span><i>Mage\/Catalog\/Block\/Product\/Price.php<\/i><i><span style=\"font-weight: 400;\"> block. <\/span><\/i><span style=\"font-weight: 400;\">The <em>config.xml<\/em> would contain the following code:<\/span><\/p>\n<pre class=\"lang:xml decode:true \">&lt;blocks&gt;\r\n    &lt;catalog&gt;\r\n        &lt;rewrite&gt;\r\n            &lt;product_price&gt;Belvg_RenderPrices_Block_Catalog_Product_Price&lt;\/product_price&gt;\r\n        &lt;\/rewrite&gt;\r\n    &lt;\/catalog&gt;\r\n&lt;\/blocks&gt;\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">When the system is reloaded, the classes are being verified for the presence of any rewrites, and in case there are any &#8211; the system uses exactly the classes that are indicated in those rewrites.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now let&#8217;s see how we can use events to complete the above-given task.&#160;<\/span><span style=\"font-weight: 400;\">To make it simpler, let&#8217;s divide the process into 3 steps:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">First off, we need to define the events which our module will use.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Secondly, we have to get the object of the product and then create and assign a new property to it. The property should contain the number that is equal to the discount rate. The helper of the module will contain the method for discount percentage calculation.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Thirdly, we should create a new block which will output the information about product discount on the product and catalog pages.<\/span><\/li>\n<\/ul>\n<p><b>Step one.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s see how to choose the correct event from all events that are available in Magento.&#160;<\/span><span style=\"font-weight: 400;\">All events are generated with the help of the static method <\/span><em><span style=\"font-weight: 400;\">Mage<\/span><span style=\"font-weight: 400;\">::<\/span><\/em><span style=\"font-weight: 400;\"><em>dispatchEvent<\/em>:<\/span><\/p>\n<pre class=\"lang:php decode:true \">public static function dispatchEvent($name, array $data = array()){\r\n\tVarien_Profiler::start('DISPATCH EVENT:'.$name);\r\n\t$result = self::app()-&gt;dispatchEvent($name, $data);\r\n\tVarien_Profiler::stop('DISPATCH EVENT:'.$name);\r\n\treturn $result;\r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">To get the list of all events we need to put the following line at the beginning of the method (do not forget to delete later):<\/span><\/p>\n<pre class=\"lang:php decode:true\">Mage:: log($name, null, 'events.log', true);<\/pre>\n<p>The <i>core_block_abstract_to_html_after<\/i> event gets output in the <i>toHtml()<\/i> method of the <i>Mage_Core_Block_Abstract<\/i> class from which Magento blocks are inherited. The method returns HTML content into blocks, while transport object is transmitted into the <i>core_block_abstract_to_html_after <\/i>event which contains HTML code of the block:<\/p>\n<pre class=\"lang:php decode:true\">self::$_transportObject-&gt;setHtml($html);\r\nMage::dispatchEvent('core_block_abstract_to_html_after',\r\n\tarray('block' =&gt; $this, 'transport' =&gt; self::$_transportObject));\r\n$html = self::$_transportObject-&gt;getHtml();\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">With the help of <\/span><span style=\"font-weight: 400;\">transport object,<\/span><span style=\"font-weight: 400;\">&#160;it is possible to set up the output of our custom block.&#160;<\/span><span style=\"font-weight: 400;\">Besides, we will require to use two more events of the model:&#160;<\/span><i>catalog_product_load_after<\/i> and <i>catalog_product_collection_load_after<\/i>.&#160;<span style=\"font-weight: 400;\">These events <\/span><span style=\"font-weight: 400;\">are called after the data has been loaded into the product model.<\/span><\/p>\n<p><b>Step two.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">We need to register handlers for <\/span><i>catalog_product_load_after<\/i> <span style=\"font-weight: 400;\">and<\/span> <i>catalog_product_collection_load_after.&#160;<\/i><span style=\"font-weight: 400;\">Add the following code into the module&#8217;s<\/span><span style=\"font-weight: 400;\"> config.xml <\/span><span style=\"font-weight: 400;\">file:<\/span><\/p>\n<pre class=\"lang:xml decode:true\">&lt;events&gt;\r\n  &lt;catalog_product_load_after&gt;\r\n        &lt;observers&gt;\r\n            &lt;product_load_after&gt;\r\n            \t&lt;class&gt;belvg_render_prices\/observer&lt;\/class&gt;\r\n            \t&lt;method&gt;catalog_product_load_after&lt;\/method&gt;\r\n            &lt;\/product_load_after&gt;\r\n        &lt;\/observers&gt;\r\n\t&lt;\/catalog_product_load_after&gt;\r\n\t&lt;catalog_product_collection_load_after&gt;\r\n        &lt;observers&gt;\r\n  \t      &lt;catalog_product_collection_load_after&gt;\r\n            \t&lt;class&gt;belvg_render_prices\/observer&lt;\/class&gt;\r\n            \t&lt;method&gt;catalog_product_collection_load_after&lt;\/method&gt;\r\n            &lt;\/catalog_product_collection_load_after&gt;\r\n        &lt;\/observers&gt;\r\n\t&lt;\/catalog_product_collection_load_after&gt;\r\n&lt;\/events&gt;\r\n<\/pre>\n<p>All events that are used by the module are described within the events node. The next thing we are going to use is the node of the event name (you may check it in the first parameter <em>Mage::dispatchEvent<\/em>). Then, inside observers we should describe our handlers: indicate the name of the handler class and the method which logic will be applied. It is considered a good practice to give the handler method the same name as the event name.<\/p>\n<p><span style=\"font-weight: 400;\">Now let&#8217;s write down the method that will calculate the discount rate from the original product price.<\/span><span style=\"font-weight: 400;\"> For that we need to register a helper class in the config file:<\/span><\/p>\n<pre class=\"lang:xml decode:true \">&lt;helpers&gt;\r\n    &lt;belvg_render_prices&gt;\r\n        &lt;class&gt;Belvg_RenderPrices_Helper&lt;\/class&gt;\r\n    &lt;\/belvg_render_prices&gt;\r\n&lt;\/helpers&gt;\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">Create a helper class and include the calculation method into it:<\/span><\/p>\n<pre class=\"lang:php decode:true \">class Belvg_RenderPrices_Helper_Data extends Mage_Core_Helper_Abstract {\r\n\tpublic function calcDiscountPercentForSpecialPrice($product){\r\n    \tif($product) {\r\n        \t$specialPrice = $product-&gt;getSpecialPrice();\r\n        \t$price = $product-&gt;getPrice();\r\n        \tif($price &amp;&amp; $specialPrice) {\r\n            \t$res = 100 - (round(($specialPrice * 100) \/ $price, 0, PHP_ROUND_HALF_DOWN));\r\n            \treturn $this-&gt;__(\"You Save %s%%\", $res);\r\n            }\r\n        \treturn null;  }}\r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">Add a new property to the product object:<\/span><\/p>\n<pre class=\"lang:php decode:true \">public function catalog_product_load_after(Varien_Event_Observer $observer){\r\n\tif(Mage::helper('belvg_render_prices')-&gt;isAllowedConfig()){\r\n    \t$product = $observer-&gt;getData('product');\r\n    \tif ($product &amp;&amp; $product-&gt;getSpecialPrice() &amp;&amp; $product-&gt;getPrice() &gt; 0) {\r\n        \t$save = Mage::helper('belvg_render_prices')-&gt;calcDiscountPercentForSpecialPrice($product);\r\n        \tif($save){\r\n            \t$product-&gt;setSave($save);\r\n            }  } }\r\n}\r\npublic function catalog_product_collection_load_after(Varien_Event_Observer $observer){\r\n\tif(Mage::helper('belvg_render_prices')-&gt;isAllowedConfig()) {\r\n    \t$collection = $observer-&gt;getEvent()-&gt;getCollection();\r\n    \tforeach ($collection as $product) {\r\n        \t$save = Mage::helper('belvg_render_prices')-&gt;calcDiscountPercentForSpecialPrice($product);\r\n        \t$product-&gt;setData('save', $save);\r\n        }  }\r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">To add a new property we are going to use the default Magento possibility that lets you dynamically receive and assign new properties to objects with the help of &#160;<\/span><em>_get() <\/em><span style=\"font-weight: 400;\">and &#160;<\/span><i>_set()<\/i><span style=\"font-weight: 400;\"> methods.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The thing is that Magento models are using the functionality of the <em>Varien_Object<\/em> class. The class&#8217;s constructor receives one optional argument &#8211; an array of data which is saved into the<em> $_data<\/em> property. &#160;<\/span><span style=\"font-weight: 400;\">This class redefines php methods, thanks to which it is possible to get access to object data.<\/span><span style=\"font-weight: 400;\"> &#160;<\/span><span style=\"font-weight: 400;\">Besides, here is implemented the interface for ArrayAccess, which allows calling objects data with the help of square brackets.<\/span><\/p>\n<p><b>Step three.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Registering a handler for the event <\/span><i>core_block_abstract_to_html_after:<\/i><\/p>\n<pre class=\"lang:xml decode:true \">&lt;events&gt;\r\n    &lt;core_block_abstract_to_html_after&gt;\r\n        &lt;observers&gt;\r\n            &lt;belvg_render_prices_after&gt;\r\n            \t&lt;class&gt;belvg_render_prices\/observer&lt;\/class&gt;\r\n            \t&lt;method&gt;core_block_abstract_to_html_after&lt;\/method&gt;\r\n            &lt;\/belvg_render_prices_after&gt;\r\n        &lt;\/observers&gt;\r\n\t&lt;\/core_block_abstract_to_html_after&gt;\r\n&lt;\/events&gt;\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">Let&#8217;s describe in the observer class the logic of adding a block that contains the information about the product discount.<\/span><\/p>\n<pre class=\"lang:php decode:true \">public function core_block_abstract_to_html_after(Varien_Event_Observer $observer){\r\n   if(Mage::helper('belvg_render_prices')-&gt;isAllowedConfig())  {\r\n   \tif ('catalog\/product_price' == $observer-&gt;getBlock()-&gt;getType() &amp;&amp; 'catalog\/product\/view\/tierprices.phtml' != $observer-&gt;getBlock()-&gt;getTemplate()) {\r\n       \t$transport = $observer-&gt;getEvent()-&gt;getTransport();\r\n       \t$block = $observer-&gt;getEvent()-&gt;getBlock();\r\n       \t$youSaveBlock = $block\r\n           \t-&gt;getLayout()\r\n               -&gt;createBlock(\r\n               \t'core\/template',\r\n               \t'you_save',\r\n               \tarray(\r\n                   \t'template' =&gt; 'belvg\/after.phtml'\r\n               \t)\r\n           \t)-&gt;setProduct($block-&gt;getProduct());\r\n       \t$transport-&gt;setHtml($transport-&gt;getHtml().$youSaveBlock-&gt;toHtml());\r\n       }\r\n   }\r\n   return $this;\r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">Here we create a new <\/span><i>&#8216;you save&#8217;<\/i><span style=\"font-weight: 400;\">&#160; block and register a new <\/span><em>&#8216;belvg\/after.phtml&#8217;<\/em><span style=\"font-weight: 400;\"> template which will output the information about the discount.&#160;<\/span><span style=\"font-weight: 400;\">The parameter <\/span><em><span style=\"font-weight: 400;\">$observer <\/span><\/em><span style=\"font-weight: 400;\">of the observer method is an object through which we can receive the data which is being transmitted via the <\/span><em>dispatchEvent()<\/em><span style=\"font-weight: 400;\"> method in the second parameter.&#160;<\/span><span style=\"font-weight: 400;\">In our case with the help of <\/span><em><span style=\"font-weight: 400;\">$block <\/span><span style=\"font-weight: 400;\">= <\/span><span style=\"font-weight: 400;\">$observer&#8594;getEvent()&#8594;getBlock() <\/span><\/em><span style=\"font-weight: 400;\">we have received a block and created another custom block inside it<\/span><span style=\"font-weight: 400;\">.&#160;<\/span><span style=\"font-weight: 400;\">Basically, that is all.<\/span><span style=\"font-weight: 400;\"> The task is complete. Here is the <a href=\"https:\/\/github.com\/belvg-public\/Belvg_RenderPrices\">link<\/a> to the module.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"First off, let&#8217;s nail down the task that we need to complete. We have to &#8230;","protected":false},"author":22,"featured_media":13032,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-13031","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-magento","post_format-post-format-image"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"We have to create a module that should output the following text line on product and catalog pages: &quot;You have saved XXX%&quot; (where XXX is a whole number defining the discount rate), provided that the product is set to a special price (a discount price).\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Mikhail Soiko\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#article\",\"name\":\"How To Show Discount Savings in Magento | BelVG Blog\",\"headline\":\"How To Show Discount Savings in Magento\",\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/How-To-Show-Discount-Savings-in-Magento.jpg\",\"width\":770,\"height\":209,\"caption\":\"How To Show Discount Savings in Magento\"},\"datePublished\":\"2017-05-02T17:35:38+02:00\",\"dateModified\":\"2025-02-11T08:20:57+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#webpage\"},\"articleSection\":\"Magento, Image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"position\":2,\"name\":\"Magento\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#listItem\",\"name\":\"How To Show Discount Savings in Magento\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#listItem\",\"position\":3,\"name\":\"How To Show Discount Savings in Magento\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko#author\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko\",\"name\":\"Mikhail Soiko\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1603d45135617d53877de2d9ffe112a497830fa8a92f16dd13b43069b1e53482?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Mikhail Soiko\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#webpage\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html\",\"name\":\"How To Show Discount Savings in Magento | BelVG Blog\",\"description\":\"We have to create a module that should output the following text line on product and catalog pages: \\\"You have saved XXX%\\\" (where XXX is a whole number defining the discount rate), provided that the product is set to a special price (a discount price).\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/How-To-Show-Discount-Savings-in-Magento.jpg\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html\\\/#mainImage\",\"width\":770,\"height\":209,\"caption\":\"How To Show Discount Savings in Magento\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-show-discount-savings-in-magento.html#mainImage\"},\"datePublished\":\"2017-05-02T17:35:38+02:00\",\"dateModified\":\"2025-02-11T08:20:57+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How To Show Discount Savings in Magento | BelVG Blog","description":"We have to create a module that should output the following text line on product and catalog pages: \"You have saved XXX%\" (where XXX is a whole number defining the discount rate), provided that the product is set to a special price (a discount price).","canonical_url":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#article","name":"How To Show Discount Savings in Magento | BelVG Blog","headline":"How To Show Discount Savings in Magento","author":{"@id":"https:\/\/belvg.com\/blog\/author\/mishell-soiko#author"},"publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2017\/05\/How-To-Show-Discount-Savings-in-Magento.jpg","width":770,"height":209,"caption":"How To Show Discount Savings in Magento"},"datePublished":"2017-05-02T17:35:38+02:00","dateModified":"2025-02-11T08:20:57+02:00","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#webpage"},"isPartOf":{"@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#webpage"},"articleSection":"Magento, Image"},{"@type":"BreadcrumbList","@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/belvg.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","position":2,"name":"Magento","item":"https:\/\/belvg.com\/blog\/category\/magento","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#listItem","name":"How To Show Discount Savings in Magento"},"previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#listItem","position":3,"name":"How To Show Discount Savings in Magento","previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}}]},{"@type":"Organization","@id":"https:\/\/belvg.com\/blog\/#organization","name":"BelVG Blog","description":"Magento and Prestashop articles","url":"https:\/\/belvg.com\/blog\/"},{"@type":"Person","@id":"https:\/\/belvg.com\/blog\/author\/mishell-soiko#author","url":"https:\/\/belvg.com\/blog\/author\/mishell-soiko","name":"Mikhail Soiko","image":{"@type":"ImageObject","@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/1603d45135617d53877de2d9ffe112a497830fa8a92f16dd13b43069b1e53482?s=96&d=mm&r=g","width":96,"height":96,"caption":"Mikhail Soiko"}},{"@type":"WebPage","@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#webpage","url":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html","name":"How To Show Discount Savings in Magento | BelVG Blog","description":"We have to create a module that should output the following text line on product and catalog pages: \"You have saved XXX%\" (where XXX is a whole number defining the discount rate), provided that the product is set to a special price (a discount price).","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/belvg.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#breadcrumblist"},"author":{"@id":"https:\/\/belvg.com\/blog\/author\/mishell-soiko#author"},"creator":{"@id":"https:\/\/belvg.com\/blog\/author\/mishell-soiko#author"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2017\/05\/How-To-Show-Discount-Savings-in-Magento.jpg","@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html\/#mainImage","width":770,"height":209,"caption":"How To Show Discount Savings in Magento"},"primaryImageOfPage":{"@id":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html#mainImage"},"datePublished":"2017-05-02T17:35:38+02:00","dateModified":"2025-02-11T08:20:57+02:00"},{"@type":"WebSite","@id":"https:\/\/belvg.com\/blog\/#website","url":"https:\/\/belvg.com\/blog\/","name":"BelVG Blog","description":"Magento and Prestashop articles","inLanguage":"en-US","publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"13031","title":"How To Show Discount Savings in Magento | #site_title","description":"We have to create a module that should output the following text line on product and catalog pages: &quot;You have saved XXX%&quot; (where XXX is a whole number defining the discount rate), provided that the product is set to a special price (a discount price).","keywords":null,"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-11-03 18:37:19","updated":"2026-11-03 18:37:19"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/category\/magento\" title=\"Magento\">Magento<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHow To Show Discount Savings in Magento\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/belvg.com\/blog\/"},{"label":"Magento","link":"https:\/\/belvg.com\/blog\/category\/magento"},{"label":"How To Show Discount Savings in Magento","link":"https:\/\/belvg.com\/blog\/how-to-show-discount-savings-in-magento.html"}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/13031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/comments?post=13031"}],"version-history":[{"count":9,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/13031\/revisions"}],"predecessor-version":[{"id":28644,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/13031\/revisions\/28644"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media\/13032"}],"wp:attachment":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media?parent=13031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/categories?post=13031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/tags?post=13031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}