Post by Jax22 » Wed Sep 23, 2020 11:15 am

Hi all, could use a little help here. I am using opencart 3.0.3.6. I have at least figured out how to display more text between the product number and the availability on the product page, and have added "Is Complete" and "Condition", both of which will be a simple yes or no. I have added both fields to the oc_product table as varchar(6) and filled in the fields for my test product.

On the product page, the titles show up, but I cannot seem to pull the info from the database.

I have edited the template language file to include:

Code: Select all

                'product_id'       => $query->row['product_id'],
		'name'             => $query->row['name'],
                'cond'             => $query->row['cond'],
                'complete'         => $query->row['complete'],         
		'description'      => $query->row['description'],
		
and edited the catalog/view/template/default/product/product.twig file to include

Code: Select all

               <li>{{ text_condition }} {{ cond }}</li>
               <li>{{ text_complete }} {{ complete }}</li>
               
and the controller/product/product.php to include

Code: Select all

            $data['model'] = $product_info['model'];
            $data['cond'] = $product_info['cond'];
            $data['complete'] = $product_info['complete'];
            $data['reward'] = $product_info['reward'];
But the strings from the database are not being displayed. What exactly am I missing here? If I can figure out how to pull what I need from the oc_product table, I can figure out the admin part ok, so if anyone has any suggestions, I could use them. Thank you.

Newbie

Posts

Joined
Wed Sep 23, 2020 11:03 am

Post by OSWorX » Wed Sep 23, 2020 3:07 pm

Jax22 wrote:
Wed Sep 23, 2020 11:15 am
But the strings from the database are not being displayed. What exactly am I missing here? If I can figure out how to pull what I need from the oc_product table, I can figure out the admin part ok, so if anyone has any suggestions, I could use them. Thank you.
I would say you need also to adopt the model to send back the new fields/values.

Btw: extending core tables is never a good idea!
Better to create a table and store and pull the data from there and combine them in the controller.
Doing so will help in future updates.

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by Jax22 » Sun Sep 27, 2020 4:55 am

Thanks for the reply -

I realize I should be using another table, but at this point, I'm more concerned about just getting it to work for now.
I am even more confused than ever with this. I added 2 fields, Product Condition (New/Used) and Complete (All pieces present (if used)).
The condition comes up just fine - reads from the database, shows changes made ...etc. Perfect.
Followed the exact same steps for the other one and no luck getting it to even show up. Ugh!

Newbie

Posts

Joined
Wed Sep 23, 2020 11:03 am

Post by OSWorX » Sun Sep 27, 2020 3:39 pm

Jax22 wrote:
Sun Sep 27, 2020 4:55 am
Followed the exact same steps for the other one and no luck getting it to even show up. Ugh!
Be more precise, post what and where you did the changes.
Without knowing about what you are talking exactly, it is hard to help.

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by Jax22 » Mon Sep 28, 2020 10:29 am

Sorry, you are right. I can make this easier though. I downloaded a modification found at: https://www.opencart.com/index.php?rout ... H0oVbCCA8L which is supposed to show the SKU on a product page. The instructions were fairly simple -

Add to template/product/product.twig:

Code: Select all

{% if sku %}
            <li>{{ text_sku }} {{ sku }}</li>
            {% endif %}
Add to language/*/product/product.php:

Code: Select all

$_['text_sku']              = 'SKU:';
Add to controller/product/product.php:

Code: Select all

$data['sku'] =$product_info['sku'];
A very simple update to show SKU from the product table, much as I was doing with my previous attempts at getting this to work. However, once the changes are made, cache is cleared in /storage/ ...etc, SKU number is added to product and verified in database that it was saved, I still get absolutely nothing on the product page under SKU, or even the text showing "SKU:" ...

Newbie

Posts

Joined
Wed Sep 23, 2020 11:03 am

Post by letxobnav » Mon Sep 28, 2020 10:43 am

just add:

Code: Select all

$this->log->write($data,true));
before:

Code: Select all

$this->response->setOutput($this->load->view('product/product', $data));
in your product controller so you can see what is send to the view in your oc error log and that will tell you if it is a controller/model issue or a view issue.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by JNeuhoff » Mon Sep 28, 2020 4:22 pm

letxobnav wrote:
Mon Sep 28, 2020 10:43 am
just add:

Code: Select all

$this->log->write($data,true));
before:

Code: Select all

$this->response->setOutput($this->load->view('product/product', $data));
in your product controller so you can see what is send to the view in your oc error log and that will tell you if it is a controller/model issue or a view issue.
Won't work, the system/library/log.php write function won't accept a 2nd argument. Use something like this:

Code: Select all

ob_start();var_dump($data);$this->log->write(ob_get_contents());ob_end_clean();

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by sw!tch » Mon Sep 28, 2020 5:28 pm

JNeuhoff wrote:
Mon Sep 28, 2020 4:22 pm

Won't work, the system/library/log.php write function won't accept a 2nd argument. Use something like this:
I think he meant

Code: Select all

$this->log->write(print_r($data,true));

Backup and [ learn how to recover ] before you make any changes.


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by OSWorX » Mon Sep 28, 2020 5:30 pm

JNeuhoff wrote:
Mon Sep 28, 2020 4:22 pm
letxobnav wrote:
Mon Sep 28, 2020 10:43 am
just add:

Code: Select all

$this->log->write($data,true));
before:

Code: Select all

$this->response->setOutput($this->load->view('product/product', $data));
in your product controller so you can see what is send to the view in your oc error log and that will tell you if it is a controller/model issue or a view issue.
Won't work, the system/library/log.php write function won't accept a 2nd argument. Use something like this:

Code: Select all

ob_start();var_dump($data);$this->log->write(ob_get_contents());ob_end_clean();

Code: Select all

$this->log->write($data,true));
will never work (produce error), because one ) too much ..

Another possibility would be:

Code: Select all

$this->log->write( print_r( $data, true ) );
Here the second ) is correct.

And - just for the experienced users - one more (writes the message into the server log), usefull also when $this->log is not available like in the system files:

Code: Select all

error_log( print_r( $data, true ) );
For further options for this see: https://www.php.net/manual/en/function.error-log

And a fourth - if $this is not available (see system files):

Code: Select all

$log = new \Log('error.log');
$log->write( print_r( $data, true ) );
Initialize a new log and write.
nb: name of logfile can be somewhat ..

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by letxobnav » Mon Sep 28, 2020 6:28 pm

right, I meant:

Code: Select all

$this->log->write(print_r($data,true));

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Jax22 » Mon Sep 28, 2020 11:21 pm

Actually, with the 2nd ) removed, the first works just fine and showed up in my error log.

The SKU number is apparently being sent from the database:

Code: Select all

[tab_review] => Reviews (0)
    [product_id] => 50
    [manufacturer] => 
    [manufacturers] => https://xyz.com/index.php?route=product/manufacturer/info&amp;manufacturer_id=
    [sku] => 121223
    [model] => 60220
    [reward] => 
    [points] => 0
    ...etc
    
But just not shown on the product page for some reason. Followed the installation instructions to the T, double and triple checked, so unsure as to why it's still not showing up...

Newbie

Posts

Joined
Wed Sep 23, 2020 11:03 am

Post by OSWorX » Tue Sep 29, 2020 12:04 am

Okay, when you have all values inside the $data array, simply call this in your template (as already mentioned):

Code: Select all

{% if sku %}
   <li>{{ text_sku }} {{ sku }}</li>
{% endif %}
If the SKU is NOT inside the $data array, you have to assign it into.

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by letxobnav » Tue Sep 29, 2020 12:11 am

I think you are editing the wrong view file.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Jax22 » Tue Sep 29, 2020 2:53 am

OSWorX wrote:
Tue Sep 29, 2020 12:04 am
Okay, when you have all values inside the $data array, simply call this in your template (as already mentioned):

Code: Select all

{% if sku %}
   <li>{{ text_sku }} {{ sku }}</li>
{% endif %}
If the SKU is NOT inside the $data array, you have to assign it into.
Please forgive me for sounding like a complete noob, but I pretty much am. I am assuming you mean in the template/default/product/product.twig, yes? That code has been added. I am assuming, hopefully correctly, that the sku is assigned as the log file returned the value of the sku from the database. This is why I am confused... it SHOULD be showing up. I have even tried to remove the {% if sku % } to at least see if it would add the text "SKU:" to the product page even without a value, but the label text doesn't show either. I have it set correctly in the catalog/language/en-gb/product/product.php file:

Code: Select all

<?php
// Text
$_['text_search']              = 'Search';
$_['text_brand']               = 'Brand';
$_['text_manufacturer']        = 'Brand:';
$_['text_model']               = 'Product Code:';
$_['text_sku']                 = 'SKU:';
...etc

Newbie

Posts

Joined
Wed Sep 23, 2020 11:03 am

Post by sw!tch » Tue Sep 29, 2020 3:27 am

You need to clear your theme cache.
Admin -> Dashboard -> Cog Icon on top right.. Refresh it or turn it off if developing/testing twig changes.

If you have modifications also editing product controllers or twig then you need to also refresh your modification cache.
Admin -> Extensions -> Modifications -> Refresh your modification cache.

If changes are still not showing after the above: You have either used the theme editor, which is taking priority over your twig or the implementation is incorrect.

Backup and [ learn how to recover ] before you make any changes.


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm
Who is online

Users browsing this forum: thekrotek and 25 guests