Hikashop with HTTP get or put action

  • Posts: 33
  • Thank you received: 0
9 years 1 month ago #247360

-- url of the page with the problem -- : www.realflightshop.com
-- HikaShop version -- : 2.6.3
-- Joomla version -- : 3.6.2

Hi

Thanks for the great work here.

I want to know whether Hikashop can have call by HTTP get or put to other sever to callback action after customer purchase an product.

For example, when customer purchase product A, Hikashop system will call by HTTP get or put (which we have another server url)to another server to callback .

Thanks!

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

  • Posts: 33
  • Thank you received: 0
9 years 1 month ago #247361

And i hope the action is initiate after the order status become confirmed.
And it is product specific, some product need to initiate action and some product don't.

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

  • Posts: 26275
  • Thank you received: 4045
  • MODERATOR
9 years 1 month ago #247364

Hi,

Thanks to a Joomla plugin you can do it ; you just need to use the HikaShop order triggers to know when an order is confirmed ("onAfterOrderCreate" and "onAfterOrderUpdate")
www.hikashop.com/support/documentation/6...mentation.html#order

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 33
  • Thank you received: 0
9 years 1 month ago #247386

Hi

Thanks you for kindly reply and great support.

How can I set for specific product or specific vendor.
I need to create pugin or I need to modify history.php file?

And where to put the HTTP callback get url

Sorry I am a new commer to HTTP Callbak

Thanks!

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

  • Posts: 33
  • Thank you received: 0
9 years 1 month ago #247396

Is that I need to create a plugin for onAfterOrderCreate.
But how can I specific that plugin to specific vendor product?
Thanks!

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

  • Posts: 33
  • Thank you received: 0
9 years 1 month ago #247400

Hi
Or can you write the code for me to reference.
I hope the trigger will initiate after specific product purchase and order status became confirmed, and a http callback will sent to a url.
And in url, it need to acquire user email and order number.

It's really headach to me
Thanks

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

  • Posts: 84313
  • Thank you received: 13702
  • MODERATOR
9 years 1 month ago #247394

Hi,

As Jerome explained, you need to create a new joomla plugin of the group "hikashop" :
docs.joomla.org/Portal:Plugin_Development
And in that plugin, you need to implement the "onAfterOrderCreate" and "onAfterOrderUpdate" triggers. In these functions, you'll get a $order variable with either the whole order data, or only the order_id and the order_status:
www.hikashop.com/support/documentation/6...ntation.html#objects
So you might need to use the loadFullOrder function call to load the order:
www.hikashop.com/support/documentation/6...umentation.html#code
And you can also check that the order_status is confirmed like that:
if($order->order_status != 'confirmed') return;

Then, after checking the products and the status, you can do your HTTP call, with cURL:
www.startutorial.com/articles/view/php-curl

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

  • Posts: 33
  • Thank you received: 0
9 years 1 month ago #247477

Hi

Thanks for excellent support.

I have try to write it as follow, but I have several question, how do I judge the order product is the product that I want to trigger this event, is that use $order->order_name?

And how to acquire the order email or order number in url, is this also use $order->order_id in url string.

And could you check for my writing, thanks!

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.6.3
 * @author	hikashop.com
 * @copyright	(C) 2010-2016 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgHikashopDash extends JPlugin {
	function plgHikashopDash (&$subject, $config){
		parent::__construct($subject, $config);
protected $autoloadLanguage = true;

	}

	// Call a trigger, in this example: onBeforeOrderCreate

onAfterOrderCreate(&$order,&$send_email)
{
		// Actions to do when my trigger is called
	}

onAfterOrderUpdate(&$order,&$send_email)
{
		// Actions to do when my trigger is called
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }
function< loadFullOrder>()
{

$orderClass = hikashop_get('class.order');
$order = $orderClass->loadFullOrder($order_id, true, false);
Similarly to the cart, the products will be available in the attribute as an array of product objects:
$order->products
}

if($order->order_status != 'confirmed') return;
	}


\\curl
$cSession = curl_init(); 
curl_setopt($cSession,CURLOPT_URL," http://realflight.com:8080/realflight/pages/<callbackName>.jsp?email= $order->order_email &ordern=C54438&prodid=GO_PILOT");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false); 
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;
?>

Last edit: 9 years 1 month ago by nicolas.

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

  • Posts: 84313
  • Thank you received: 13702
  • MODERATOR
9 years 1 month ago #247485

Hi,

You have several problems with your code:

1. constructors should be named __construct and not the name of the class to be able to support new versions of PHP.
2. in the onAfterOrderCreate function, you don't have any code.
3. onAfterOrderUpdate misses the "function" text before and the function< loadFullOrder>() line is totally weird.
4. The $order_id in your code comes from nowhere. You need to get it from the $order object.
5. As explained in the documation, the products are available in $order->products and if you look in the order object provided in the documentation, you'll see that the products are in an array, and that each element of the array is an object containing the data of each product.

So to sum it up, the code should be:

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.6.3
 * @author	hikashop.com
 * @copyright	(C) 2010-2016 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgHikashopDash extends JPlugin {
	function __construct (&$subject, $config){
		parent::__construct($subject, $config);
protected $autoloadLanguage = true;

	}

	// Call a trigger, in this example: onBeforeOrderCreate

onAfterOrderCreate(&$order,&$send_email)
{
		// Actions to do when my trigger is called
}

onAfterOrderUpdate(&$order,&$send_email)
{
		// Actions to do when my trigger is called
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }

$orderClass = hikashop_get('class.order');
$order = $orderClass->loadFullOrder($order->order_id, true, false);
$do = false;
foreach( $order->products as $product){
 if($product->order_product_name == 'my product name') $do = true;
}

if(!$do) return;
if($order->order_status != 'confirmed') return;



\\curl
$cSession = curl_init(); 
curl_setopt($cSession,CURLOPT_URL," http://realflight.com:8080/realflight/pages/<callbackName>.jsp?email=".$order->customer->user_email. "&ordern=". $order->order_number."&prodid=GO_PILOT");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false); 
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;
}
}
?>
Please note that this is a user support forum. We can't work on custom development for you. If you can't do it on your own with the hint we give you, you'll have to contact a 3rd party developer to help you with that.

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

Time to create page: 0.045 seconds
Powered by Kunena Forum