Shipment costs credited to hikamarket vendor

  • Posts: 78
  • Thank you received: 4
  • Hikamarket Multivendor Hikashop Business
9 years 10 months ago #186880

Hi,
I have a product that is sold from a vendor Person A. Person A get the fee for the sale. eg.. 10%.
But the shipment of this product is done from Person B or Person C, depending on the country of the order (2 warehouses for the same product).

Shipment selection is based on country.
Person B and Person C are also registered as hikamarket vendors.

Can I somehow achieve that the shipment costs (fees) are automatically credited to Person B or Person C in hikamarket ?

Thanks

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 10 months ago #186898

Hi,

Well, that's something possible using a custom plugin.
The idea is to create a special sub sale of the shipping vendor (B or C) depending the shipping address.

By not spliting the shipping fees to the vendors, the shipping price will only be on the main order.
Then, you can create a new sub-order for the "shipping vendor" with a "fake" product which will have the price of the shipping fees.
Thanks to that, the customer won't see any modification for his orders but you will insert your shipping vendors in the process.

The other solution would be to transform the shipping price into a product in the main order.
But I prefer the first solution because the customer does not see any difference in the 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: 78
  • Thank you received: 4
  • Hikamarket Multivendor Hikashop Business
9 years 10 months ago #187003

Thanks. Sounds good.
Do I only need to create the suborders ?
Status update of orders will be handled automatically then ?
You have some sample code of creating suborders with the API ?

Thanks and br

Last edit: 9 years 10 months ago by tgdkere2.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 10 months ago #187043

Hi,

By creating a sub order, HikaMarket will include it in his processing.
A sub order is an HikaShop order with the order_type "subsale" and with the "order_parent_id" set with the "order_id" of his parent.

To use the API, you need to create a PHP empty object (stdClass) and fill it with the data you want to save in the database.
Then you can use the "save" function of the HikaShop order class to save and create the sub order.
The HikaMarket class order have some functions to create sub orders but they are "private", the parameters and the structure is mostly internal so I prefer to not make public functions for that. Even if you can call directly the function, you can see the code in order to help you.

The idea is to use the trigger "onAfterOrderCreate" that HikaShop is already using.
Here some sample code ; please understand that I wrote it like that and I didn't test it (so it could have some misspellings or mistakes)

public function onAfterOrderCreate(&$order, &$send_email) {
	if(empty($order) || empty($order->order_type) || $order->order_type != 'sale')
		return;
	if(isset($order->hikamarket->do_not_process))
		return;

	/** TODO
	 * define $vendor_id
	 */
	$o = new stdClass();
	$o->order_type = 'subsale';
	$o->order_parent_id = $order->order_id;
	$o->order_vendor_id = $vendor_id;

	$o->order_partner_id = 0;
	$o->order_partner_price = 0.0;
	$o->order_payment_price = 0.0;
	$o->order_shipping_price = 0.0;
	$o->order_shipping_tax = 0.0;
	$o->order_discount_price = 0.0;
	$o->order_discount_tax = 0.0;
	$o->order_discount_code = '';

	// Create the order product
	//
	$p = new stdClass();
	$p->product_id = 0;
	$p->cart_product_id = 0;
	$p->order_product_quantity = 1;
	$p->order_product_name = JText::_('SHIPPING');
	$p->order_product_code = 'shipping';
	$p->order_product_price = $order->order_shipping_price;
	$p->order_product_vendor_price = $order->order_shipping_price;
	$p->no_update_qty = true;

	// Create the order "cart" and put the product into
	//
	$o->cart = new stdClass();
	$o->cart->products = array(
		$p
	);

	// Reprocess full price
	//
	$shopOrderClass = hikashop_get('class.order');
	$shopOrderClass->recalculateFullPrice($o, $o->cart->products);

	$o->order_vendor_price = $o->order_full_price;

	// Store internal data
	//
	$o->hikamarket = new stdClass();
	$o->hikamarket->internal_process = true;
	$o->hikamarket->send_email = true;
	$o->hikamarket->parent = $order;

	$order_id = $shopOrderClass->save($o);
}
It should be a good start to generate a sub sale with the price of the shipping.

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.

Moderators: Obsidev
Time to create page: 0.053 seconds
Powered by Kunena Forum