Unable to install override class from module in PrestaShop 1.7.5.2

On start:

  1. Server: Apache2
  2. DB: MySQL 5.7
  3. PrestaShop 1.7.5.2 (fresh install)
  4. PHP 7.2

I create custom module where i try to override class: Customer (located in root dir of prestashop in folder classes/Customer.php) So i created folder in my module ovveride/classes/ and put my code:

    <?php
use PrestaShop\PrestaShop\Adapter\ServiceLocator;
use PrestaShop\PrestaShop\Adapter\CoreException;


/***
 * Class CustomerCore
 */
class CustomerCore extends ObjectModel
{
    public function customHook()
    {
        $isSuccess = $this->isLogged($withGuest = false);

        if ($isSuccess == true) {
            Hook::exec('actionCustomerLoginAfter', array('customer' => $this));
        }
    }
}

And that looks folder strucute: enter image description here

When i install module, evrything looks good BUT

  1. The file (Customer.php) did not copy to override/classes/
  2. When i try enable module i see error: Cannot enable module adminnotify. Unable to install override: Class CustomerOverride5cf26a545fb27 does not exist

I try with:

  1. clear cache (didnt work)
  2. manual remove cache (didnt work)
  3. I check filenames, folder structure (looks good)

Thx all for help :)

Upvotes: 1

Views: 1533

Answers (1)

Ok problem solved :) In this case i creat ovveride when i try to redefine class CustomerCore with orginal extends. In ovveride we must create new class and extends to core class (in this case CustomerCore). So in this case new Customer class looks like

<?php
    class Customer extends CustomerCore {
     //your own code
}

Upvotes: 3

Related Questions