Jump to content

1.7.7 How should we override src\Adapter AdminProductDataProvider?


qian.li.ok@gmail.com

Recommended Posts

Hi, I want to add supplier reference in the back office Products page, and I have created my own module so I can keep the PrestaShop code untouched. I've managed to have the webpage updated with the new column by override the twig files in my module. 

But now the new column isn't populated with the supplier reference value, after some hours of tracing, I've found that src\Adapter\Product\AdminProductDataProvider's getCatalogProductList method needs to be updated to include the `supplier_reference`  column in the sqlSelect. It works by updating the PS source code, but I still hope that I can keep PS core sourcecode clean and untouched, so I'm wondering if anyone may recommend how I should override the Adapter DataProvider cleanly? Many thanks in advance. 

Link to comment
Share on other sites

Hi Jo, many thanks for your reply. In that case,  if we need to update the SELECT SQL to pull out more data, how should I do it without changing the PS DataProvider code? I really hope that I can do it without touching core source code. I've already created my own module to override a few twig files. Is that something possible we can achieve with my module? 

Link to comment
Share on other sites

  • 8 months later...

src/ can be override in module for example class /src/Adapter/PDF/OrderInvoicePdfGenerator.php:

 

file1: /modules/someModule/src/OrderInvoicePdfGenerator.php

-- copy of file OrderInvoicePdfGenerator.php and changed namespace to  PrestaShop\Module\someModule\Controller;

 

file2: /modules/someModul/config/services.yml:

services:
    _defaults:
      public: true
    prestashop.adapter.pdf.order_invoice_pdf_generator:
      class: PrestaShop\Module\someModule\Controller\OrderInvoicePdfGenerator
      arguments:
        - '@translator'

file3: /modules/someModul/composer.json

    "autoload": {
        "psr-4": {
            "PrestaShop\\Module\\someModule\\": "src/"
          },
...

 

Edited by damian_pm (see edit history)
  • Like 4
Link to comment
Share on other sites

  • 1 year later...

This doesn't seem to work.  I am attempting to override:

src/Adapter/PDF/PDFGenerator.php

I created the following file in my module:

modules/mymodule/src/Adapter/PDF/PDFGenerator.php

and in module services.yml:

  prestashop.adapter.pdf.pdf_generator:
    class: PrestaShop\Module\MyModule\Adapter\PDF\PDFGenerator
    arguments:
      - '@=service("prestashop.adapter.legacy.context").getContext().smarty'
      - '@=service("templateTypeProvider")'

and the contents of the override file (modules/mymodule/src/Adapter/PDF/PDFGenerator.php)

namespace PrestaShop\Module\MyModule\Adapter\PDF;

use PrestaShop\PrestaShop\Adapter\Entity\PDF;
use PrestaShop\PrestaShop\Core\PDF\PDFGeneratorInterface;
use PrestaShop\PrestaShop\Core\PDF\PDFTemplateTypeProviderInterface;
use Smarty;

/**
 * Class PDFManager responsible for PDF generation using legacy code.
 */
final class PDFGenerator implements PDFGeneratorInterface
{
    public function generatePDF(array $objectCollection)
    {
        print "override";
        die;
    }
}

and of course composer.json contains the path to /src

Any ideas what's going wrong?

 

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...

Good Day Guys

I m really surprise about this issue:

Prestashop Store : 1.7.8.10

i m unable to delete products as well i mean product will be deleted but i always get error so in debug Mode i found the following error:

AdminProductDataUpdater->deleteProduct() received an unknown ID.[Exception 5005]

 public function deleteProduct($productId)
    {
        $product = new Product($productId);
        if (!Validate::isLoadedObject($product)) {
            throw new \Exception('AdminProductDataUpdater->deleteProduct() received an unknown ID.', 5005);
        }
        // dumb? no: delete() makes a lot of things, and can reject deletion in specific cases.
        // Hooks: will trigger actionProductDelete
        $result = $product->delete();

I kindly ask if above mentioned error can be even involved by Cloudflare service

Thanks in adevance

 

 

Link to comment
Share on other sites

On 11/16/2023 at 12:58 PM, Maurice said:

Good Day Guys

I m really surprise about this issue:

Prestashop Store : 1.7.8.10

i m unable to delete products as well i mean product will be deleted but i always get error so in debug Mode i found the following error:

AdminProductDataUpdater->deleteProduct() received an unknown ID.[Exception 5005]

 public function deleteProduct($productId)
    {
        $product = new Product($productId);
        if (!Validate::isLoadedObject($product)) {
            throw new \Exception('AdminProductDataUpdater->deleteProduct() received an unknown ID.', 5005);
        }
        // dumb? no: delete() makes a lot of things, and can reject deletion in specific cases.
        // Hooks: will trigger actionProductDelete
        $result = $product->delete();

I kindly ask if above mentioned error can be even involved by Cloudflare service

Thanks in adevance

 

 

But which ID is received? Check the backtrace too.

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...