- Posts: 88
- Thank you received: 20
Delete product from order from PHP
4 years 7 months ago #341056
by dyvel
Delete product from order from PHP was created by dyvel
-- HikaShop version -- : 4.5.1
-- Joomla version -- : 4.x
Hi
I'm creating a script to handle batch refunding on orders of a specific product. If an order contains more than this specific product, I want to remove it from the order and add a history note with the refund.
I know how to save or modify an order and add history to it, but does Hikashop has a built-in function to remove a product from an order or can you recommend a way to do this?
Merci
-- Joomla version -- : 4.x
Hi
I'm creating a script to handle batch refunding on orders of a specific product. If an order contains more than this specific product, I want to remove it from the order and add a history note with the refund.
I know how to save or modify an order and add history to it, but does Hikashop has a built-in function to remove a product from an order or can you recommend a way to do this?
Merci
Please Log in or Create an account to join the conversation.
4 years 7 months ago - 4 years 7 months ago #341057
by dyvel
Replied by dyvel on topic Delete product from order from PHP
I figured it out.
For anyone else interested in this, this is a simplified version of the code to delete a product from an order:
It removes the product from $modifyOrder->products - however It's not saving as expected.
For anyone else interested in this, this is a simplified version of the code to delete a product from an order:
Code:
$orderClass = hikashop_get('class.order');
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }
if ( ($key = array_search($product->product_id, $order->products) ) !== false) {
$product_id = $order->products[$key]->product_id;
$order_product_id = $order->products[$key]->order_product_id;
}
$modifyOrder = new stdClass();
$modifyOrder->order_id = $order->order_id;
$modifyOrder->product = new stdClass();
$modifyOrder->product->product_id = $product_id;
$modifyOrder->product->order_product_id = $order_product_id;
$modifyOrder->product->order_product_quantity = 0;
$orderClass->save($modifyOrder);
It removes the product from $modifyOrder->products - however It's not saving as expected.
Last edit: 4 years 7 months ago by dyvel.
Please Log in or Create an account to join the conversation.
4 years 7 months ago #341059
by nicolas
Replied by nicolas on topic Delete product from order from PHP
Hi,
I would rather do like this:
That's basically the code in the task "product_remove" of the "order" controller, which is behind the delete button of each product on the listins of products of an order on the backend interface.
I would rather do like this:
Code:
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }
if ( ($key = array_search($product->product_id, $order->products) ) !== false) {
$product_id = $order->products[$key]->product_id;
$order_product_id = $order->products[$key]->order_product_id;
}
hikaInput::get()->set('cid', $order->order_id);
hikaInput::get()->set('order_product_id', $order_product_id);
$orderClass = hikashop_get('class.order');
$status = $orderClass->saveForm('product_delete');
Please Log in or Create an account to join the conversation.
Time to create page: 0.048 seconds