Post by itrends » Wed Dec 07, 2011 5:01 am

Hi there.

I wondered if it is possible to display a message on the basket page if there is less than 5 left of a product?

Ideally this would be listed next to each product in the basket that it applies too.

Any ideas on how I might do this would be greatly appreciated.

Many thanks in advance :)

Active Member

Posts

Joined
Tue Jul 14, 2009 7:54 pm

Post by straightlight » Wed Dec 07, 2011 5:40 am

I don't know why only the cart quantity was added but not the product quantity in stock while it has been used only within the cart library to compare the results. This topic should be moved to the feature requests section since this is a pretty good one.

The following modifications would be on a core file so I would suggest to make a backup before applying this.

In your system/library/cart.php file,

find:

Code: Select all

'quantity'        => $quantity,
add right below:

Code: Select all

'product_quantity'        => (int)$product_query->row['quantity'],
Then, in your catalog/controller/checkout/cart.php file,

find:

Code: Select all

$this->data['column_quantity'] = $this->language->get('column_quantity');
add below:

Code: Select all

$this->data['column_product_quantity'] = $this->language->get('column_product_quantity');
Then, find:

Code: Select all

'quantity' => $product['quantity'],
add below:

Code: Select all

'product_quantity' => $product['product_quantity'],
Then, in your language/english/checkout/cart.php file,

find:

Code: Select all

$_['column_quantity'] = 'Quantity';
add after:

Code: Select all

$_['column_product_quantity'] = 'Left In Stock';
Then, in your catalog/view/theme/x/template/checkout/cart.tpl file,

find:

Code: Select all

<td class="quantity"><?php echo $column_quantity; ?></td>
add below:

Code: Select all

<td class="quantity"><?php echo $column_product_quantity; ?></td>
find:

Code: Select all

<td class="quantity"><input type="text" name="quantity[<?php echo $product['key']; ?>]" value="<?php echo $product['quantity']; ?>" size="3" /></td>
add below:

Code: Select all

<td class="quantity">(<?php echo $product['product_quantity']; ?>)</td>
This should do it.
Last edited by straightlight on Wed Dec 07, 2011 6:24 am, edited 1 time in total.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by itrends » Wed Dec 07, 2011 6:08 am

Thanks. Before I implement this, might I ask, will this ONLY show if there are 5 or less of a given item left? I just want to show a message saying "Quick, stock is low" but not actually tell them how much stock is left.

I won't bore you with the reasons why :)

Thank you again for the quick reply.

Active Member

Posts

Joined
Tue Jul 14, 2009 7:54 pm

Post by straightlight » Wed Dec 07, 2011 6:20 am

This modification is for every quantity but to apply your case specifically, in cart.tpl file,

find:

Code: Select all

<td class="quantity">(<?php echo $column_product_quantity; ?>: <?php echo $product['product_quantity']; ?>)</td>
replace with:

Code: Select all

<?php if ($product['quantity'] > 0 && $product['quantity'] <= 5) { ?>
<td class="quantity">(<?php echo $column_product_quantity; ?>: <?php echo $product['product_quantity']; ?>)</td>
<?php } ?>
This should work as intended.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by itrends » Wed Dec 07, 2011 6:22 am

Thank you. I'll give it a try shortly.

Active Member

Posts

Joined
Tue Jul 14, 2009 7:54 pm

Post by straightlight » Wed Dec 07, 2011 6:25 am

No problem. In the mean time, I adjusted a slight step in my first post so to be a bit more presentable from template.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by khnaz35 » Sat Sep 15, 2018 7:40 pm

itrends wrote:
Wed Dec 07, 2011 6:22 am
Thank you. I'll give it a try shortly.
How does it go for you did it work ?

Always help others it's always come back, give and receive :)


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm

Post by khnaz35 » Sat Sep 15, 2018 7:42 pm

straightlight wrote:
Wed Dec 07, 2011 5:40 am
I don't know why only the cart quantity was added but not the product quantity in stock while it has been used only within the cart library to compare the results. This topic should be moved to the feature requests section since this is a pretty good one.

The following modifications would be on a core file so I would suggest to make a backup before applying this.

In your system/library/cart.php file,

find:

Code: Select all

'quantity'        => $quantity,
add right below:

Code: Select all

'product_quantity'        => (int)$product_query->row['quantity'],
Then, in your catalog/controller/checkout/cart.php file,

find:

Code: Select all

$this->data['column_quantity'] = $this->language->get('column_quantity');
add below:

Code: Select all

$this->data['column_product_quantity'] = $this->language->get('column_product_quantity');
Then, find:

Code: Select all

'quantity' => $product['quantity'],
add below:

Code: Select all

'product_quantity' => $product['product_quantity'],
Then, in your language/english/checkout/cart.php file,

find:

Code: Select all

$_['column_quantity'] = 'Quantity';
add after:

Code: Select all

$_['column_product_quantity'] = 'Left In Stock';
Then, in your catalog/view/theme/x/template/checkout/cart.tpl file,

find:

Code: Select all

<td class="quantity"><?php echo $column_quantity; ?></td>
add below:

Code: Select all

<td class="quantity"><?php echo $column_product_quantity; ?></td>
find:

Code: Select all

<td class="quantity"><input type="text" name="quantity[<?php echo $product['key']; ?>]" value="<?php echo $product['quantity']; ?>" size="3" /></td>
add below:

Code: Select all

<td class="quantity">(<?php echo $product['product_quantity']; ?>)</td>
This should do it.
Will this work on OC 2.3.0.2 as well or just on 1.XX

Always help others it's always come back, give and receive :)


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Who is online

Users browsing this forum: No registered users and 17 guests