Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product cancel hook doesn't fire when refunding only shipping costs #1405

Open
andrewrowanwallee opened this issue Jul 5, 2022 · 2 comments

Comments

@andrewrowanwallee
Copy link

We have a use case whereby a merchant wishes to be able to refund only the shipping costs, not any part of the item. We need to be able to register this refund in our payment module but the hookActionProductCancel doesn't fire if no product is being cancelled. Is there a way to hook into shipping costs refunds? Thanks

@andrewrowanwallee
Copy link
Author

@prestaforum any ideas?

@Kasvaja
Copy link

Kasvaja commented Apr 24, 2024

  1. Create a Custom Hook
    Since PrestaShop is modular and allows for extensive customization, you can create a custom hook that specifically deals with shipping cost refunds. Here's how you can define a new hook:

php
Copy code
// Register the hook in your module's install function
public function install() {
return parent::install() &&
$this->registerHook('actionRefundShippingCosts');
}

// Implement the hook execution logic in your module
public function hookActionRefundShippingCosts($params) {
// Add your logic to handle the refund of shipping costs here
}
2. Trigger the Hook Manually
You need to find a place in your PrestaShop files (most likely in a controller or a class that deals with order handling) where the refund process for shipping costs is decided. In that place, you can manually trigger the custom hook you've created:

php
Copy code
// Assuming $order and $shippingRefundAmount are defined
Hook::exec('actionRefundShippingCosts', [
'order' => $order,
'amount' => $shippingRefundAmount
]);
3. Adjust the Order Total Manually
Since this action doesn't natively exist in PrestaShop, you may also need to manually adjust the order totals and possibly interact with the payment module to process the refund:

php
Copy code
$order->total_paid -= $shippingRefundAmount;
$order->total_paid_tax_incl -= $shippingRefundAmount;
$order->total_paid_tax_excl -= $shippingRefundAmount; // Adjust according to whether your shipping costs are taxed or not
$order->update();
4. Log the Refund for Reporting
Make sure to log these operations appropriately. You can use PrestaShop's OrderSlip class to create a record of the refund:

php
Copy code
$order_slip = new OrderSlip();
$order_slip->id_customer = (int)$order->id_customer;
$order_slip->id_order = (int)$order->id_order;
$order_slip->conversion_rate = 1; // Modify based on your needs
$order_slip->total_shipping_cost = $shippingRefundAmount;
$order_slip->add();
5. Test Thoroughly
Since this is a customization outside the standard PrestaShop workflows, thoroughly test this feature across different scenarios to ensure stability and reliability.

  1. Consider the Payment Gateway
    Consult with your payment gateway provider or documentation to handle the actual refund process correctly. This might require API calls or other integrations to ensure the refunded amount is processed back through the customer's original payment method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants