Post by Xciso » Sun Dec 03, 2017 7:44 pm

Hi. I am now going to upgrade a module from 2.x to 3.x
In the file "catalog/product/product.php" i want to insert "$data['xxx'] = $product_info['xxx'];" for my code.
But when I have it like that I get "Undefined variable"

If I type "$xxx = $product_info['xxx'];" it works.

In the module for v2.x it worked great with "$data['xxx'] = $product_info['xxx'];" , but not in 3.x
Is it safe to use "$xxx = $product_info['xxx'];" ?

I want my code below this in product.php

Code: Select all

$data['model'] = $product_info['model'];
			$data['reward'] = $product_info['reward'];
			$data['points'] = $product_info['points'];
Thanks.

Active Member

Posts

Joined
Fri Jul 15, 2011 5:20 am

Post by straightlight » Sun Dec 03, 2017 10:22 pm

Code: Select all

$xxx = $product_info['xxx'];
for:

Code: Select all

$data['xxx'] = $product_info['xxx'];
and the theme file you will be calling:

Code: Select all

{% if xxx %}
{{ xxx }}
{% endif %}
must be relative to the method name you are declaring this variable from the route you are using on the URL in order to call the controller. If the theme is not declared or if all caches have not been cleared after the changes, the results may not appear at all or instantaneously.

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 Xciso » Sun Dec 03, 2017 11:44 pm

Hi. Thanks for your answer. That is exactly what i have done.
When i type:

Code: Select all

$data['xxx'] = $product_info['xxx'];
I get "Undefiend variable".

Do you want to take a look at my code?

Active Member

Posts

Joined
Fri Jul 15, 2011 5:20 am

Post by straightlight » Mon Dec 04, 2017 12:09 am

You either uploaded your PHP file in a non-utf8 unicode format which would corrupt the PHP file or you did not added this line into the right method as the way being described on my previous post which must also match within the same method where the theme file is instantiated.

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 Xciso » Mon Dec 04, 2017 12:42 am

Hi again. The file is UTF-8 (without BOM), Everything works, but not when it is typed "$data", Is it needed to have "$data". What is that for?
This mod are not changing anything in the template file, as it work togerther with (stock).

Part of my vqmod

Code: Select all

	<file name="catalog/controller/product/product.php">
		<operation error="log">
            <search><![CDATA[$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');]]></search>
            <add position="after"><![CDATA[
			$mpsu = $product_info['mpsu'];
			$mpssf = $product_info['mpssf'];
			$mpsss = $product_info['mpsss'];
			$mpsst = $product_info['mpsst'];
			$mpsrf = $product_info['mpsrf'];
			$mpsrs = $product_info['mpsrs'];
			$mpsrt = $product_info['mpsrt'];
			$mpsre = $product_info['mpsre'];]]></add>
        </operation>
		<operation error="log">
            <search><![CDATA[$data['stock'] = $product_info['stock_status'];]]></search>
            <add position="replace"><![CDATA[$ch = curl_init($mpsu);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			$text = curl_exec($ch);
			$mpssf = stripos($text, $mpssf);
			$mpsss = stripos($text, $mpsss);
			$mpsst = stripos($text, $mpsst);

			if ($mpsu == false) {
			$data['stock'] = $product_info['stock_status'];
			}
			elseif ($mpssf == true) {
			$data['stock'] = $product_info['mpsrf'];
			}			
			elseif ($mpsss == true) {
			$data['stock'] = $product_info['mpsrs'];
			}
			elseif ($mpsst == true) {
			$data['stock'] = $product_info['mpsrt'];
			}
			else {
			$data['stock'] = $product_info['mpsre'];
			}]]></add>
        </operation>
    </file>
    

Active Member

Posts

Joined
Fri Jul 15, 2011 5:20 am

Post by straightlight » Mon Dec 04, 2017 1:10 am

This extension does not include your OC version nor does not indicate into which method of the targeted controller files you want to integrate new variables.

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 Xciso » Mon Dec 04, 2017 1:16 am

Hi straightlight. Sadly I dont understand what you mean. My OC version is 3.0.2.0.
As you can see I need to type without "$data", when I type with it I get undefined variable.
What is $data for?

Active Member

Posts

Joined
Fri Jul 15, 2011 5:20 am

Post by straightlight » Mon Dec 04, 2017 2:45 am

The codes above are incomplete. For instance, what is the $text variable for? The only $text variable I see from this controller file is for the duration of the product. Please post a complete solution.

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
Who is online

Users browsing this forum: No registered users and 421 guests