Sort by product_code in mail

  • Posts: 45
  • Thank you received: 0
9 years 9 months ago #223610

-- HikaShop version -- : 2.6.0. Business

Hi,

I want to sort the products in the notification mail by product_code. How can I get this done?

Thanks!

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

  • Posts: 26274
  • Thank you received: 4045
  • MODERATOR
9 years 9 months ago #223622

Hi,

It will require some custom code in your email "preload".
When you edit an email in the HikaShop backend (HikaShop business required), you have three parts (html, text, preload).

The preload is the PHP code which generate the content data for the html/text parts.
In that preload code, you will find that :

		$cartProducts[] = $cartProduct;
	}
	$templates['PRODUCT_LINE'] = $cartProducts;
You need to insert the "$cartProduct" in the "$cartProducts" array but with the product code as key. So after the addition of all products in the array, you can sort the array by the array key (which will be the product code).

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: 45
  • Thank you received: 0
9 years 9 months ago #223697

Hi Jerome,

Thanks for your answer.

I tried the following:
Around line 120 of the preload version I changed the array code to:

//$cartProducts = array();
// ADDED FOR SORTING IN EMAIL
$cartProducts = array($item->order_product_code => $cartProduct );
ksort($item->order_product_code);
// END ADDITION
$cartFooters = array();

But this didn't have effect in the email. Probably I did something wrong.

Can you help me a bit more?

Thanks!

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

  • Posts: 84306
  • Thank you received: 13701
  • MODERATOR
9 years 9 months ago #223722

Hi,

Your code is not correct.
The line:

$cartProducts[] = $cartProduct;
should be replaced by:
$cartProducts[$item->order_product_code] = $cartProduct;
and then, you should add the line:
ksort($cartProducts);
before the line:
$templates['PRODUCT_LINE'] = $cartProducts;

The following user(s) said Thank You: Squashtoppertje

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

  • Posts: 45
  • Thank you received: 0
9 years 9 months ago #223857

Yes, this works. Thanks a lot!

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

Time to create page: 0.059 seconds
Powered by Kunena Forum