Support
Quality
Security
License
Reuse
kandi has reviewed dropship and discovered the below as its top functions. This is intended to give you an instant insight into dropship implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
automatic dependency resolution
automatic classpath construction
aliases to simplify common dropship tasks
offline mode
download-only mode
See all related Code Snippets
QUESTION
Validate an order before is placed in Prestashop Module
Asked 2021-Nov-25 at 07:16I'm developing a Prestashop module to achieve this.
When an order with a specific product is placed I need to contact an external API to perform some write operations. To be more specific, some product will be automiatically ordered on a third party platform. It's not dropshipping, I'm sending the order to the producer of the goods.
The problem is, if the API call goes bad i must stop the order from being placed and notify the client that something has gone wrong, keeping the cart intact if possibile.
Everything else is working: i can detect the products, send the info to the third party api and read the response. Except I'm using a Module with this code:
$this->registerHook('actionValidateOrder');
It is my understanding this hook is called after an order is placed, so I can't block it if the API call goes wrong.
What is the right way to approach this scenario?
I tried to use actionOrderStatusPostUpdate
but I don't think i can have prior knowledge on the order status (payment methods can vary).
Any idea? Seems like a basic task to accomplish but I'm stuck.
Using Prestashop 1.7.8
ANSWER
Answered 2021-Nov-25 at 07:16Do you need to validate the order? Because PrestaShop's order-related hooks are only available once the order has been created.
Wouldn't a better solution be to check the cart when a product is added by the customer?
hookActionCartSave
In this case, you could avoid disappointed customers by letting them know at the time of adding the product to the basket that the products is not available.
Update - Create a custom hook Unfortunately, there is no hook to stop the order from being validated and created. - but you can create one
Register a new custom hook, for example actionValidateOrderBefore. Register the hook in your module:
$this->registerHook('actionValidateOrderBefore')
and exec the hook in the PaymentModule
(classes/PaymentModule.php) class validateOrder
method (public function validateOrder() ..)
Hook::exec('actionValidateOrderBefore', [id_cart] => $id_cart);
Reset your module, and you have you can manipulate the order before being created.
If you want to do it very nicely, you can create an override for validateOrder method of the PaymentModul class https://devdocs.prestashop.com/1.7/modules/concepts/overrides/
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
See Similar Libraries in
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source