Thanks
Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.
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
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:
Attachments
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.
products_quantity variable has not been posted on your behalf to state where this variable originates from. More info is needed.drest341 wrote: ↑Fri Jul 09, 2021 4:18 pmThe 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:
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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
I did it before but doesn't pass the value on product page, Paul.paulfeakins wrote: ↑Fri Jul 09, 2021 6:04 pmYou 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']) ); }
Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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'];
after ...
Code: Select all
<li><?php echo $text_stock; ?> <?php echo $stock; ?></li>
add ...
<?php echo "CURRENT PRODUCT ITEMS IN CART: " . $products_quantity; ?>
Thanks for help!
Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.
Dear straightlight i am using OC 2.3, but problem was solved, thanks again for your time.straightlight wrote: ↑Fri Jul 09, 2021 8:15 pmPost 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.
Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.
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.drest341 wrote: ↑Fri Jul 09, 2021 8:20 pmSolved:
in catalog/controller/product/product.php
after ...
$data['products'] = array();
add ...and in catalog/view/theme/default/template/product/product.tplCode: Select all
foreach ($this->cart->getProducts() as $product) { $data['products'][] = array( 'products_quantity' => $product['quantity'] ); } $data['products_quantity'] = $product['quantity'];
after ...Make refresh Modifications after change!Code: Select all
<li><?php echo $text_stock; ?> <?php echo $stock; ?></li> add ... <?php echo "CURRENT PRODUCT ITEMS IN CART: " . $products_quantity; ?>
Thanks for help!
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.
Users browsing this forum: Semrush [Bot] and 151 guests