How to Create / Duplicate an order through API?

  • Posts: 12
  • Thank you received: 0
9 years 10 months ago #185564

-- HikaShop version -- : 2.3.5
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.5
-- Browser(s) name and version -- : XXX
-- Error-message(debug-mod must be tuned on) -- : Hi


Hi

Im trying to figure out a way to convert a product into a recurring payment, but cannot find out how to create/duplicate a whole order.
There is plenty of examples to interact with an order, but that part is already in place.

So, How to create a new or duplicate an existing (whole) order through HS API?

Last edit: 9 years 10 months ago by cgonline.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #185576

Hi,

Please give us more details on when you want to create / duplicate and order, on creation of the main order, when status updated, any time ?

If its any time, for any order you can use the order class. Get the desired order thanks to:

$order_id = 1; // desired value
$orderClass = hikashop_get('class.hikashop');
$fullOrder = $orderClass->loadFullOrder($order_id);

Then edit the PHP object, remove the order_id, etc and save it thanks to:
$orderClass->save($fullOrder);

The following user(s) said Thank You: cgonline

Please Log in or Create an account to join the conversation.

  • Posts: 12
  • Thank you received: 0
9 years 10 months ago #185784

Hi Xavier

It is actually not from within any hikashop process I want to duplicate an order, but from the outside (from my own plugin triggered remotely).
It looks quite easy from your example though.
Will the call to save() trigger the normal HS plugins/events or must I do that afterwards (nice to know regarding email notifications sent off when a payment automaticly occurs after a month/an interval)?

And - One final question (I hope :) )..
Is it possible to get a direct link to a product, with regards to the sef setting "use canonical and generate if missing"?
Im using this in my email template, but it looks like this method (or any of the other route methods) do not return any canonical links set on products?

$r = hikashop_completeLink('product&task=show&cid='.$target['hs_id'].'&name='.$target['hs_alias'].'&Itemid=738');

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
9 years 10 months ago #185794

Hi,

Yes, the call to save will trigger the normal HikaShop plugins/events.
For a direct link which handles the canonical URLs, you want to use:

$product_object = new stdClass();
$product_object->product_canonical = $target['hs_canonical'];
$r = hikashop_contentLink('product&task=show&cid='.$target['hs_id'].'&name='.$target['hs_alias'].'&Itemid=738',$product_object);
The best though would be to have a $product_object coming from the database with all the product data as the object attributes, like we do in HikaShop since hikashop_contentLink expect an object, not an array.

Please Log in or Create an account to join the conversation.

Time to create page: 0.073 seconds
Powered by Kunena Forum