Matt E Posted October 8, 2022 Share Posted October 8, 2022 (edited) I would like to add the product reference before the name of each product when creating new order on back-end where the arrow is in this screenshot... I have found searchProductsAction function in "PrestaShopBundle\Controller\Admin\Sell\Order\OrderController" which uses SearchProducts and FoundProduct controllers located here: use PrestaShop\PrestaShop\Core\Domain\Product\Query\SearchProducts; use PrestaShop\PrestaShop\Core\Domain\Product\QueryResult\FoundProduct; Also, I see these results are assembled by the admin\themes\new-theme\public\order_create.bundle.js script using the $name attribute of the $foundProducts array from an AJAX call. As an experiment, I was able to change what was displayed in the results list by modifying the $name variable in the FoundProduct.php core controller, like this: However this file does not declare the $reference variable like it does in the nearby ProductDetails.php controller. In fact, trying to declare and return any other variable in FoundProduct.php results in a 500 error when performing the search function. I was able to succsesfully remap the admin_orders_products_search route to a custom controller to override the searchProductsAction function, but I am stuck on how to correctly modify the $name attribute to include the $reference for each $foundProduct before returning it to the order_create.bundle.js script to display the results, and do so using an override instead of actually editing the core controller file. Can someone more experienced please advise the correct procedure to achieve this? Edited October 8, 2022 by Matt E (see edit history) Link to comment Share on other sites More sharing options...
Ali Samie Posted October 8, 2022 Share Posted October 8, 2022 This is an interesting topic and I would like to know if someone has an idea for this. Link to comment Share on other sites More sharing options...
ps8modules Posted October 9, 2022 Share Posted October 9, 2022 Hi. Did you mean something like this? Link to comment Share on other sites More sharing options...
ps8modules Posted October 9, 2022 Share Posted October 9, 2022 (edited) Three files need to be edited. 1. AdminDir/themes/new-theme/public/order_create.bundle.js unminify this JavaScript here: https://unminify.com/ find: key: "renderFoundProducts", change to: key: "renderFoundProducts", value: function (e) { (0, o.default)(e).forEach(function (e) { var t = e.name; var tr = e.reference; 0 === e.combinations.length && (t += " - " + e.formattedPrice), c(a.default.productSelect).append('<option value="' + e.productId + '">' + tr+ ': '+t + "</option>"); }); }, 2. src/Core/Domain/Product/QueryResult/FoundProduct.php add reference variable: change __construct to: public function __construct( int $productId, string $reference, string $name, string $formattedPrice, float $priceTaxIncl, float $priceTaxExcl, float $taxRate, int $stock, string $location, bool $availableOutOfStock, array $combinations = [], array $customizationFields = [] ) { $this->productId = $productId; $this->reference = $reference; $this->name = $name; $this->formattedPrice = $formattedPrice; $this->priceTaxIncl = $priceTaxIncl; $this->priceTaxExcl = $priceTaxExcl; $this->taxRate = $taxRate; $this->stock = $stock; $this->location = $location; $this->availableOutOfStock = $availableOutOfStock; $this->combinations = $combinations; $this->customizationFields = $customizationFields; } add new function after getProductId(): /** * @return string */ public function getReference(): string { return $this->reference; } 3. src/Adapter/Product/QueryHandler/SearchProductsHandler.php add reference to FoundProduct: 4. Come back here and give me a Like by clicking the gray heart below my posts 😄 Edited October 9, 2022 by 4you.software (see edit history) Link to comment Share on other sites More sharing options...
Matt E Posted October 11, 2022 Author Share Posted October 11, 2022 On 10/9/2022 at 12:54 AM, 4you.software said: Three files need to be edited. Thanks for the reply, it was helpful to make some progress, but unfortunately I need to do this without overriding the core files. I am trying to override or decorate the SearchProducts query handler (prestashop.adapter.product.query_handler.search_products) or class (PrestaShop\PrestaShop\Adapter\Product\QueryHandler\SearchProductsHandler) using a custom module... I already defined the class/namespace with composer.json and routes.yml. I know this is working because I successfully override the OrderController.php to my custom version. Next I created modules\MyModule\config\Services.yml: services: _defaults: public: true prestashop.adapter.product.query_handler.search_products: class: 'MyModule\Controller' Then I copied SearchProductsHandler.php from src\Adapter\Product\QueryHandler to modules\MyModule\src\Controller change the namespace to MyModule\Controller and made some small changes to the functions to test if it's working. Now when I try to do the search on the create order page, console logs 500 error with this message: [MissingHandlerException code 0]: Missing handler for command PrestaShop\\PrestaShop\\Core\\Domain\\Product\\Query\\SearchProducts This is confusing because when I run terminal command "php bin/console debug:container search_products" I get this response: Information for Service "prestashop.adapter.product.query_handler.search_products" ================================================================================== ---------------- ---------------------------------------------------------- Option Value ---------------- ---------------------------------------------------------- Service ID prestashop.adapter.product.query_handler.search_products Class MyModule\Controller Tags - Public yes Synthetic no Lazy no Shared yes Abstract no Autowired no Autoconfigured no ---------------- ---------------------------------------------------------- Can someone explain why the 500 error when the SearchProducts handler service seems correctly re-mapped to the module? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now