Page 1 of 1
$data['xxx'] = $product_info['xxx']; - Undefined variable
Posted: Sun Dec 03, 2017 7:44 pm
by Xciso
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.
Re: $data['xxx'] = $product_info['xxx']; - Undefined variable
Posted: Sun Dec 03, 2017 10:22 pm
by straightlight
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.
Re: $data['xxx'] = $product_info['xxx']; - Undefined variable
Posted: Sun Dec 03, 2017 11:44 pm
by Xciso
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?
Re: $data['xxx'] = $product_info['xxx']; - Undefined variable
Posted: Mon Dec 04, 2017 12:09 am
by straightlight
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.
Re: $data['xxx'] = $product_info['xxx']; - Undefined variable
Posted: Mon Dec 04, 2017 12:42 am
by Xciso
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>
Re: $data['xxx'] = $product_info['xxx']; - Undefined variable
Posted: Mon Dec 04, 2017 1:10 am
by straightlight
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.
Re: $data['xxx'] = $product_info['xxx']; - Undefined variable
Posted: Mon Dec 04, 2017 1:16 am
by Xciso
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?
Re: $data['xxx'] = $product_info['xxx']; - Undefined variable
Posted: Mon Dec 04, 2017 2:45 am
by straightlight
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.