4

In OpenCart 3.0.2.0, I'm trying to get the category & product pages to display the "SKU" variable for each product. The variable is in the database, along with other product data, but for some ungodly reason, OpenCart doesn't have an option to display it. You can display the product name, price, stock availability, etc, but not the SKU.

Does anyone know how to do this specifically in OC 3? They've switched from PHP to Twig for the templates, and I'm not sure what I'm doing wrong but the method I was using in OC 2.0 is NOT working in 3.0.

{{ product.href }} displays the product URL
{{ product.description }} displays the description
{{ product.price }} displays the price
...but {{ product.sku }} or {{ sku }} or {{ product['sku'] }} does NOTHING.
TomJones999
  • 775
  • 2
  • 13
  • 30

2 Answers2

6

Try something like in default OpenCart code. This is working fine in latest opencart version 3.0.2.0

For Category page:

Step 1: Open file catalog/controller/product/category.php

Find:

'rating'      => $result['rating'],

Add after:

'sku'         => $result['sku'],


Step 2: Open file: catalog\language\en-gb(your language)\product\category.php

Find:

$_['text_price']        = 'Price:';

Add after:

$_['text_sku']        = 'SKU:';


Step 3: Open file: catalog/view/theme/default(your theme)/template/product/category.twig

Find:

<p>{{ product.description }}</p>

Add after:

{% if product.sku %}
 <p>{{ text_sku }} {{ product.sku }}</p>
{% endif %}



For Product page:

Step 1: Open file catalog/controller/product/product.php

Find:

$data['heading_title'] = $product_info['name'];

Add after:

$data['sku'] = $product_info['sku'];


Step 2: Open file: catalog\language\en-gb(your language)\product\product.php

Find:

$_['text_model']               = 'Product Code:';

Add after:

$_['text_sku']               = 'SKU:';


Step 3: Open file: catalog/view/theme/default(your theme)/template/product/product.twig

Find:

<li>{{ text_model }} {{ model }}</li>

Add after:

{% if sku %}
<li>{{ text_sku }} {{ sku }}</li>
{% endif %}
HDP
  • 4,005
  • 2
  • 36
  • 58
  • 1
    Thank you, it worked like a charm! (Also worked for displaying the stock quantity on the category page, using the same method). – TomJones999 Oct 03 '17 at 19:18
0

You can create a modification of your own and install it in opencart and make it show SKU units on products page.

It's better to output the frontend of modification in a placeholder so that it shows exactly where you want in your theme.

For example, this modification combines the product page SKU display code and outputs it the theme/.../products.twig file, however it looks for:

<!-- product_sku -->

So you don't have to guess and mess with different stuff, simply place this tag in your theme file and run the modification.

modification link: https://github.com/nabtron/opencart-ocmod-sku-product

Support & explained at: https://nabtron.com/opencart-ocmod-product-sku/

(don't forget to zip the xml file itself (not the folder)).

Nabeel Khan
  • 3,715
  • 2
  • 24
  • 37