VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: 2cool on June 01, 2017, 14:49:19 PM

Title: Total number of products on order
Post by: 2cool on June 01, 2017, 14:49:19 PM
Is it possible to add the total number of products at the order? this would help a lot for order picking.

What php code can be used and in which file?

Using vm 3.2 and joomla 3.7.2

Thanks,
Pas
Title: Re: Total number of products on order
Post by: K&K media production on June 01, 2017, 21:32:08 PM
Should be possible with a core hack or develop a vm extended plugin. Before add to cart execution check the cart quantity and return if there are to many products.
Title: Re: Total number of products on order
Post by: 2cool on June 01, 2017, 21:53:38 PM
Thanks for your reply, but I guess no check is needed :)
Just the sum of articles (2 apples, 10 beans, 5 bread = 17 products)

Regards,

Pas
Title: Re: Total number of products on order
Post by: K&K media production on June 01, 2017, 22:18:33 PM
Ah OK ... this should be inside the cart object. Make a vmdebug inside one of your cart template overrides and look what is there.
Title: Re: Total number of products on order
Post by: 2cool on June 02, 2017, 13:28:00 PM
Hi could you explain this a bit more detailed, what/where should this be done, and what should I look for?
Just need total products added at bottom of admin order.

Thanks,
Pas
Title: Re: Total number of products on order
Post by: K&K media production on June 02, 2017, 19:03:03 PM
mail_html_vendor.php

or

mail_html_vendor_more.php

$this->orderDetails['totalItems']
Title: Re: Total number of products on order
Post by: 2cool on June 03, 2017, 13:15:38 PM
Hi, I added the code to mail_html_vendor.php but gave an error 0 ?

Guess I did it wrong

<?php
// echo vmText::_('COM_VIRTUEMART_CART_MAIL_VENDOR_TITLE').$this->vendor->vendor_name.'<br/>';
echo vmText::sprintf('COM_VIRTUEMART_MAIL_VENDOR_CONTENT',$this->vendor->vendor_store_name,$this->shopperName,$this->currency->priceDisplay($this->orderDetails['details']['BT']->order_total),$this->orderDetails['details']['BT']->order_number);

if(!empty(
$this->orderDetails['details']['BT']->customer_note)){
echo '<br /><br />'.vmText::sprintf('COM_VIRTUEMART_CART_MAIL_VENDOR_SHOPPER_QUESTION',$this->orderDetails['details']['BT']->customer_note).'<br />';
echo 
vmText::$this->orderDetails['totalItems'];
}

?>
Title: Re: Total number of products on order
Post by: GJC Web Design on June 03, 2017, 13:32:17 PM
????  echo vmText::$this->orderDetails['totalItems'];

try  echo 'Total Order Items: '.$this->orderDetails['totalItems'];
Title: Re: Total number of products on order
Post by: Jörgen on June 04, 2017, 13:41:17 PM
Hello

I must miss something obvious, but the proposed solution does not work. There is no such item...
echo 'Total Order Items: '.$this->orderDetails['totalItems'];

I suggest this solution
<?php 
  $totalNrOfOrderItems
0;
  foreach (
$this->orderDetails['items'] as $orderItem) {
    
$totalNrOfOrderItems $totalNrOfOrderItems $orderItem->product_quantity
  }
  echo 
vmText::_('VM_TOTAL_NUMBER_OF_ORDER_ITEMS') . $totalNrOfOrderItems
?>


Hope that this will help.

regards

Jörgen @ Kreativ Fotografi

[edit] changed [items] to ['items'] [/edit]
Title: Re: Total number of products on order
Post by: GJC Web Design on June 04, 2017, 13:56:03 PM
Ah .. I just assumed there was cos K&K said..  ;)
Title: Re: Total number of products on order
Post by: Jörgen on June 04, 2017, 15:05:57 PM
I have just added my solution to the /templates/my-template/html/com_virtuemart/invoice/invoice_items.php and can see that it works as expected. As 2cool said, it is a nice feature for order picking.

Have a nice day

Jörgen @ Kreativ Fotografi
Title: Re: Total number of products on order
Post by: K&K media production on June 04, 2017, 17:06:36 PM
Quote from: Jörgen on June 04, 2017, 13:41:17 PM
Hello

I must miss something obvious, but the proposed solution does not work. There is no such item...
echo 'Total Order Items: '.$this->orderDetails['totalItems'];

oh sorry you're right, I just copy paste it from my template and forgot I've set this before on mail_html.php:


$totalItems = 0;
foreach($this->orderDetails['items'] as $item) {
$totalItems += $item->product_quantity;
}
$this->orderDetails['totalItems'] = $totalItems;
Title: Re: Total number of products on order
Post by: 2cool on June 06, 2017, 09:58:49 AM
Hi and thank you,
I'm almost got this right....

But I see this on orders: VM_TOTAL_NUMBER_OF_ORDER_ITEMS5

Is this just a issue in translation file? i'm using Dutch language...

Thanks and regards,

Pas
Title: Re: Total number of products on order
Post by: K&K media production on June 06, 2017, 14:49:37 PM
Quote from: 2cool on June 06, 2017, 09:58:49 AM
But I see this on orders: VM_TOTAL_NUMBER_OF_ORDER_ITEMS5

Is this just a issue in translation file? i'm using Dutch language...

This is a custom language key and you must create it

Extensions -> Languages -> Overrides
Title: Re: Total number of products on order
Post by: 2cool on June 09, 2017, 01:29:57 AM
Thanks for your help!

But I tried to do the same on a new site but can't reproduce this again :(
Get this error on mails Notice: Use of undefined constant items - assumed 'items' in /templates/mytemplate/html/com_virtuemart/invoice/invoice_items.php on line 272

Step by step:
- in /components/com_virtuemart/views/invoice/tmpl/mail_html_vendor.php add:

echo 'Total Order Items: '.$this->orderDetails['totalItems'];

- in /templates/my-template/html/com_virtuemart/invoice/invoice_items.php -> add:

<?php 
  $totalNrOfOrderItems
0;
  foreach (
$this->orderDetails[items] as $orderItem) {
    
$totalNrOfOrderItems $totalNrOfOrderItems $orderItem->product_quantity
  }
  echo 
vmText::_('VM_TOTAL_NUMBER_OF_ORDER_ITEMS') . $totalNrOfOrderItems
?>


- in /components/com_virtuemart/views/invoice/tmpl/mail_html.php -> add:

$totalItems = 0;
foreach($this->orderDetails['items'] as $item) {
$totalItems += $item->product_quantity;
}
$this->orderDetails['totalItems'] = $totalItems;


- Create a langauage override for 'VM_TOTAL_NUMBER_OF_ORDER_ITEMS'

Thanks and regards,
Pas
Title: Re: Total number of products on order
Post by: K&K media production on June 09, 2017, 01:59:45 AM
QuoteUse of undefined constant items - assumed 'items'

'items'

<?php 
  $totalNrOfOrderItems
0;
  foreach (
$this->orderDetails['items'] as $orderItem) {
    
$totalNrOfOrderItems $totalNrOfOrderItems $orderItem->product_quantity
  }
  echo 
vmText::_('VM_TOTAL_NUMBER_OF_ORDER_ITEMS') . $totalNrOfOrderItems
?>
Title: Re: Total number of products on order
Post by: Jörgen on June 09, 2017, 08:31:23 AM
Of course You are right.

I wonder why the code snippet showed [items] instead of ['items']. Could swear that I copied it from the code without editing. Bý the way, Your example shows [imems] instead of [items] ;)

Will also change my original post.

regards

Jörgen @ Kreativ Fotografi
Title: Re: Total number of products on order
Post by: 2cool on June 09, 2017, 16:05:57 PM
Thanks for your help, got one last question:

I added this to nl-NL.override.ini:
VM_TOTAL_NUMBER_OF_ORDER_ITEMS="Totaal aantal artikelen: "

This doesn't work anymore?
shows: VM_TOTAL_NUMBER_OF_ORDER_ITEMS2 on invoice mails?

Regards,
Pas
Title: Re: Total number of products on order
Post by: K&K media production on June 09, 2017, 20:31:58 PM
you need it for frontend AND backend
Title: Re: Total number of products on order
Post by: 2cool on June 10, 2017, 16:30:11 PM
Yes! works perfect real nice, thanks for your help.

Regards,

Pas