Post by drest341 » Fri Jul 09, 2021 12:59 am

Hi there, I've searched and tried various approached but using OC 2.3 I'm trying to display of individual product items already in cart (as in 3 items) on the Product page template - any ideas?
Thanks
Last edited by drest341 on Fri Jul 09, 2021 8:27 pm, edited 1 time in total.

Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens

Post by straightlight » Fri Jul 09, 2021 1:34 am

drest341 wrote:
Fri Jul 09, 2021 12:59 am
Hi there, I've searched and tried various approached but using OC 2.3 I'm trying to display of individual product items already in cart (as in 3 items) on the Product page template - any ideas?
Thanks
Of course, if no extension on the Marketplace already provides such solutions, you could either create a new extension module. Then, to specify the layout route from the OC admin pointing to the cart page. Alternatively, you could also create a new service request in the Commercial Support section of the forum to get this done as a custom job.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by drest341 » Fri Jul 09, 2021 4:18 pm

The only achievement i made is to display only the text.
Tried to grab the "$product['quantity']" from cart toggle and enter it in product controller, but in product page displays only...

Notice: Undefined variable: products_quantity in /var/www/.../catalog/view/theme/default/template/product/product.tpl on line 141
ITEMS CURRENTLY IN CART:

Image

Attachments

items_in_cart.jpg

product quantity in cart - items_in_cart.jpg (72.69 KiB) Viewed 2407 times


Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens

Post by straightlight » Fri Jul 09, 2021 6:02 pm

drest341 wrote:
Fri Jul 09, 2021 4:18 pm
The only achievement i made is to display only the text.
Tried to grab the "$product['quantity']" from cart toggle and enter it in product controller, but in product page displays only...

Notice: Undefined variable: products_quantity in /var/www/.../catalog/view/theme/default/template/product/product.tpl on line 141
ITEMS CURRENTLY IN CART:

Image
products_quantity variable has not been posted on your behalf to state where this variable originates from. More info is needed.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by paulfeakins » Fri Jul 09, 2021 6:04 pm

You should be able to pass that data down with something like this from /catalog/controller/common/cart.php:

Code: Select all

foreach ($this->cart->getProducts() as $product) {
			if ($product['image']) {
				$image = $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height'));
			} else {
				$image = '';
			}

			$option_data = array();

			foreach ($product['option'] as $option) {
				if ($option['type'] != 'file') {
					$value = $option['value'];
				} else {
					$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

					if ($upload_info) {
						$value = $upload_info['name'];
					} else {
						$value = '';
					}
				}

				$option_data[] = array(
					'name'  => $option['name'],
					'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value),
					'type'  => $option['type']
				);
			}

			// Display prices
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$unit_price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
				
				$price = $this->currency->format($unit_price, $this->session->data['currency']);
				$total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']);
			} else {
				$price = false;
				$total = false;
			}

			$data['products'][] = array(
				'cart_id'   => $product['cart_id'],
				'thumb'     => $image,
				'name'      => $product['name'],
				'model'     => $product['model'],
				'option'    => $option_data,
				'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),
				'quantity'  => $product['quantity'],
				'price'     => $price,
				'total'     => $total,
				'href'      => $this->url->link('product/product', 'product_id=' . $product['product_id'])
			);
		}

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by drest341 » Fri Jul 09, 2021 8:06 pm

paulfeakins wrote:
Fri Jul 09, 2021 6:04 pm
You should be able to pass that data down with something like this from /catalog/controller/common/cart.php:

Code: Select all

foreach ($this->cart->getProducts() as $product) {
			if ($product['image']) {
				$image = $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height'));
			} else {
				$image = '';
			}

			$option_data = array();

			foreach ($product['option'] as $option) {
				if ($option['type'] != 'file') {
					$value = $option['value'];
				} else {
					$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

					if ($upload_info) {
						$value = $upload_info['name'];
					} else {
						$value = '';
					}
				}

				$option_data[] = array(
					'name'  => $option['name'],
					'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value),
					'type'  => $option['type']
				);
			}

			// Display prices
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$unit_price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
				
				$price = $this->currency->format($unit_price, $this->session->data['currency']);
				$total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']);
			} else {
				$price = false;
				$total = false;
			}

			$data['products'][] = array(
				'cart_id'   => $product['cart_id'],
				'thumb'     => $image,
				'name'      => $product['name'],
				'model'     => $product['model'],
				'option'    => $option_data,
				'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),
				'quantity'  => $product['quantity'],
				'price'     => $price,
				'total'     => $total,
				'href'      => $this->url->link('product/product', 'product_id=' . $product['product_id'])
			);
		}
I did it before but doesn't pass the value on product page, Paul.

Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens

Post by straightlight » Fri Jul 09, 2021 8:15 pm

Post your TWIG code files. I see $data['products'] in the controller, not products_quantity so it would have to be something like: {{ product.quantity }} in the for loop on the TWIG files.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by drest341 » Fri Jul 09, 2021 8:20 pm

Solved: ;D

in catalog/controller/product/product.php
after ...
$data['products'] = array();

add ...

Code: Select all

foreach ($this->cart->getProducts() as $product) {

			$data['products'][] = array(
				'products_quantity'  => $product['quantity']
			);
		}
		$data['products_quantity'] = $product['quantity'];
and in catalog/view/theme/default/template/product/product.tpl
after ...

Code: Select all

 <li><?php echo $text_stock; ?> <?php echo $stock; ?></li>

add ...
<?php echo "CURRENT PRODUCT ITEMS IN CART: " . $products_quantity; ?>
Make refresh Modifications after change!
Thanks for help!

Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens

Post by drest341 » Fri Jul 09, 2021 8:23 pm

straightlight wrote:
Fri Jul 09, 2021 8:15 pm
Post your TWIG code files. I see $data['products'] in the controller, not products_quantity so it would have to be something like: {{ product.quantity }} in the for loop on the TWIG files.
Dear straightlight i am using OC 2.3, but problem was solved, thanks again for your time.

Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens

Post by straightlight » Fri Jul 09, 2021 8:24 pm

drest341 wrote:
Fri Jul 09, 2021 8:20 pm
Solved: ;D

in catalog/controller/product/product.php
after ...
$data['products'] = array();

add ...

Code: Select all

foreach ($this->cart->getProducts() as $product) {

			$data['products'][] = array(
				'products_quantity'  => $product['quantity']
			);
		}
		$data['products_quantity'] = $product['quantity'];
and in catalog/view/theme/default/template/product/product.tpl
after ...

Code: Select all

 <li><?php echo $text_stock; ?> <?php echo $stock; ?></li>

add ...
<?php echo "CURRENT PRODUCT ITEMS IN CART: " . $products_quantity; ?>
Make refresh Modifications after change!
Thanks for help!
Now that the variable products_quantity has been submitted once you solved the issue yourself, please add: [SOLVED] at the beginning of the subject line on your first post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by drest341 » Fri Jul 09, 2021 8:28 pm

straightlight wrote:
Fri Jul 09, 2021 8:24 pm
drest341 wrote:
Fri Jul 09, 2021 8:20 pm
Solved: ;D


Now that the variable products_quantity has been submitted once you solved the issue yourself, please add: [SOLVED] at the beginning of the subject line on your first post.
Done, best regards.

Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens
Who is online

Users browsing this forum: Semrush [Bot] and 151 guests