{"id":13630,"date":"2025-03-18T10:47:10","date_gmt":"2025-03-18T05:17:10","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=13630"},"modified":"2025-07-09T16:44:09","modified_gmt":"2025-07-09T11:14:09","slug":"override-prestashop-core-functionality","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/prestashop-tutorials\/override-prestashop-core-functionality\/","title":{"rendered":"How to Override PrestaShop Core Functionality the Right Way"},"content":{"rendered":"<p data-pm-slice=\"1 1 []\">PrestaShop allows developers to override core functionality without modifying the original files. This ensures that updates do not erase your customizations. In this guide, we will explain the right way to override PrestaShop core functionality safely and effectively.<\/p>\n<h3>Why Override Core Functionality?<\/h3>\n<p>Overriding is useful when you need to:<\/p>\n<ul data-spread=\"false\">\n<li>Modify default behaviors without changing core files.<\/li>\n<li>Extend or customize existing functionalities.<\/li>\n<li>Ensure changes are update-safe and maintainable.<\/li>\n<\/ul>\n<h3>Understanding PrestaShop&#8217;s Override System<\/h3>\n<p>PrestaShop uses an override mechanism that lets you replace core class methods without altering the original files. Overrides are stored in the <code>\/override<\/code> directory.<\/p>\n<h3>Step 1: Locating the Core File to Override<\/h3>\n<p>Identify the core file you want to modify. PrestaShop\u2019s core classes are found in:<\/p>\n<ul data-spread=\"false\">\n<li><strong>Controllers<\/strong>: <code>\/controllers\/front\/<\/code> or <code>\/controllers\/admin\/<\/code><\/li>\n<li><strong>Core Classes<\/strong>: <code>\/classes\/<\/code><\/li>\n<li><strong>Module Overrides<\/strong>: <code>\/modules\/<\/code><\/li>\n<\/ul>\n<p>For example, to override <code>Cart.php<\/code>, locate it in <code>classes\/Cart.php<\/code>.<\/p>\n<h3>Step 2: Creating the Override File<\/h3>\n<p>PrestaShop expects override files in <code>override\/<\/code> with the same namespace structure as the core files.<\/p>\n<h3>Example: Overriding <code>Cart.php<\/code><\/h3>\n<p>To override the <code>getOrderTotal()<\/code> method in <code>Cart.php<\/code>, create a new file:<\/p>\n<p><strong>Path:<\/strong> <code>\/override\/classes\/Cart.php<\/code><\/p>\n<pre><code>&lt;?php\r\nclass Cart extends CartCore\r\n{\r\n    public function getOrderTotal($withTaxes = true, $type = Cart::BOTH)\r\n    {\r\n        \/\/ Custom logic before calling the parent method\r\n        $total = parent::getOrderTotal($withTaxes, $type);\r\n        \r\n        \/\/ Example modification: Apply an additional discount\r\n        if ($total &gt; 100) {\r\n            $total -= 5; \/\/ Apply a discount of $5 for orders above $100\r\n        }\r\n        \r\n        return $total;\r\n    }\r\n}<\/code><\/pre>\n<h3>Step 3: Clearing Cache and Validating the Override<\/h3>\n<p>After adding the override, you must clear PrestaShop\u2019s cache:<\/p>\n<ol start=\"1\" data-spread=\"false\">\n<li>Navigate to <strong>Advanced Parameters &gt; Performance<\/strong>.<\/li>\n<li>Click <strong>Clear Cache<\/strong>.<\/li>\n<li>Disable and re-enable cache if necessary.<\/li>\n<\/ol>\n<p>You can also manually delete cached files from <code>\/var\/cache\/prod\/<\/code>.<\/p>\n<h3>Step 4: Testing the Override<\/h3>\n<p>Perform tests to ensure your override works:<\/p>\n<ul data-spread=\"false\">\n<li>Add products to the cart and verify the order total.<\/li>\n<li>Check for unexpected errors in logs (<code>\/var\/logs\/<\/code>).<\/li>\n<\/ul>\n<h3>Best Practices for Overriding in PrestaShop<\/h3>\n<ul data-spread=\"false\">\n<li><strong>Avoid unnecessary overrides<\/strong> \u2013 use module hooks if possible.<\/li>\n<li><strong>Document your changes<\/strong> to keep track of modifications.<\/li>\n<li><strong>Ensure compatibility<\/strong> with future PrestaShop updates.<\/li>\n<li><strong>Test overrides on a staging environment<\/strong> before deploying to live sites.<\/li>\n<\/ul>\n<h3>Conclusion<\/h3>\n<p>Overriding PrestaShop core functionality allows you to modify behaviors safely without altering core files. By following these steps, you ensure your changes are update-safe and maintainable. Always prefer hooks when possible and keep your overrides well-documented for future reference.<\/p>\n<p>Now, try applying an override in your PrestaShop store and enhance its functionality the right way!<\/p>\n<div class=\"angwp_12010 _ning_cont _ning_hidden _ning_outer _align_center responsive\" data-size=\"custom\" data-bid=\"12010\" data-aid=\"0\" style=\"max-width:800px; width:100%;height:inherit;\"><div class=\"_ning_label _left\" style=\"\"><\/div><div class=\"_ning_inner\" style=\"\"><a href=\"https:\/\/www.hiddentechies.com\/blog?_dnlink=12010&t=1782853496\" class=\"strack_cli _ning_link\" target=\"_blank\">&nbsp;<\/a><div class=\"_ning_elmt\"><img decoding=\"async\" src=\"https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/angwp\/items\/12010\/Banner-2.png\" \/><\/div><\/div><\/div><div class=\"clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>PrestaShop allows developers to override core functionality without modifying the original files. This ensures that updates do not erase your customizations. In this guide, we will explain the right way to override PrestaShop core functionality safely and effectively. Why Override Core Functionality? Overriding is useful when you need to: Modify default behaviors without changing core&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/prestashop-tutorials\/override-prestashop-core-functionality\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":13655,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[221,222,2509,2527,2139],"tags":[2548,2551,2550,2556,2554,2547,2552,2553,2549,2555],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/13630"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=13630"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/13630\/revisions"}],"predecessor-version":[{"id":13631,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/13630\/revisions\/13631"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/13655"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=13630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=13630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=13630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}