[Skip to main content](#vessel-content)

#   Delete product from order from PHP

##

- **[dyvel](/forum/user/39996-dyvel "View dyvel's Profile")**
- [![dyvel's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/39996-dyvel "View dyvel's Profile") Topic Author
- [ Offline](/forum/user/39996-dyvel)

Less More

- Posts: 88
- Thank you received: 20
-
-

4 years 7 months ago [\#341056](#341056) by [dyvel](/forum/user/39996-dyvel "View dyvel's Profile")  *[Delete product from order from PHP](/forum/30-integrations/904296-delete-product-from-order-from-php#341056 "-- 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")* was created by *[dyvel](/forum/user/39996-dyvel "View dyvel's Profile")*

-- 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

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMwLWludGVncmF0aW9ucy85MDQyOTYtZGVsZXRlLXByb2R1Y3QtZnJvbS1vcmRlci1mcm9tLXBocD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[dyvel](/forum/user/39996-dyvel "View dyvel's Profile")**
- [![dyvel's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/39996-dyvel "View dyvel's Profile") Topic Author
- [ Offline](/forum/user/39996-dyvel)

Less More

- Posts: 88
- Thank you received: 20
-
-

4 years 7 months ago -  4 years 7 months ago [\#341057](#341057) by [dyvel](/forum/user/39996-dyvel "View dyvel's Profile")  Replied by *[dyvel](/forum/user/39996-dyvel "View dyvel's Profile")* on topic *[Delete product from order from PHP](/forum/30-integrations/904296-delete-product-from-order-from-php#341057 "-- 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")*

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:
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-&gt;product_id, $order-&gt;products) ) !== false) { $product_id = $order-&gt;products[$key]-&gt;product_id; $order_product_id = $order-&gt;products[$key]-&gt;order_product_id; } $modifyOrder = new stdClass(); $modifyOrder-&gt;order_id = $order-&gt;order_id; $modifyOrder-&gt;product = new stdClass(); $modifyOrder-&gt;product-&gt;product_id = $product_id; $modifyOrder-&gt;product-&gt;order_product_id = $order_product_id; $modifyOrder-&gt;product-&gt;order_product_quantity = 0; $orderClass-&gt;save($modifyOrder);

It removes the product from $modifyOrder-&gt;products - however It's not saving as expected.

Last edit: 4 years 7 months ago by [dyvel](/forum/user/39996-dyvel "View dyvel's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMwLWludGVncmF0aW9ucy85MDQyOTYtZGVsZXRlLXByb2R1Y3QtZnJvbS1vcmRlci1mcm9tLXBocD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14325
-
-

4 years 7 months ago [\#341059](#341059) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Delete product from order from PHP](/forum/30-integrations/904296-delete-product-from-order-from-php#341059 "-- 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")*

Hi,

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-&gt;product_id, $order-&gt;products) ) !== false) { $product_id = $order-&gt;products[$key]-&gt;product_id; $order_product_id = $order-&gt;products[$key]-&gt;order_product_id; } hikaInput::get()-&gt;set('cid', $order-&gt;order_id); hikaInput::get()-&gt;set('order_product_id', $order_product_id); $orderClass = hikashop_get('class.order'); $status = $orderClass-&gt;saveForm('product_delete');

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.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMwLWludGVncmF0aW9ucy85MDQyOTYtZGVsZXRlLXByb2R1Y3QtZnJvbS1vcmRlci1mcm9tLXBocD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.040 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
