Vanilla 1.5.8a installation running on PHP 8.1.13 logging the following:
PHP Warning: Undefined variable $meta_products_price in /Users/zcdev/Sites/localhost/158atest/includes/modules/meta_tags.php on line 290.
Printable View
Vanilla 1.5.8a installation running on PHP 8.1.13 logging the following:
PHP Warning: Undefined variable $meta_products_price in /Users/zcdev/Sites/localhost/158atest/includes/modules/meta_tags.php on line 290.
Are you sure includes/modules/YOURTEMPLATE/meta_tags.php is based on includes/modules/meta_tags.php ?
I can't see a code path that yields this error.
i have my dev box running v158 with the responsive classic template; using php 8.1.12.
i am not able to reproduce this error. nor do i see what url the OP used to recreate this error. i tested any number of pages, including product pages where in theory this code would get executed.
in looking at the code, i agree that i do not understand how this var could potentially be undefined.
i also do not understand how a ZC developer since 2009 could not figure this one out on their own.
perhaps i am missing something?
Perhaps you would prefer that I fix any potential bugs in core code or modules myself and never bother to advise the dev team or original module author? That completely goes against the ethos of open source coding.
Reporting something doesn't imply that I can't "figure it out", and indeed, the variable shouldn't get to a situation where it is undefined, but clearly it is as it's there in the logs. I'll look into it further and when I find the cause I'll deal with it.
given that 3 contributors to his project have weighed in on this issue, i would hope that once you find the cause, you would share your findings here.
i can only speak for myself, and i know i am interested... and it would seem to be the ethical thing to do.
best.
It IS possible for $meta_products_price to be undefined.
When testing the scenario, only point 1 and point 2 get logged which means that in this test instanceCode:if (META_TAG_INCLUDE_PRICE == '1' and !strstr($_GET['main_page'], 'document_general')) {
error_log("point 1");
if ($product_info_metatags->fields['product_is_free'] != '1') {
error_log("point 2");
if (zen_check_show_prices() == true) {
error_log("point 3");
$meta_products_price = zen_get_products_actual_price($product_info_metatags->fields['products_id']);
$prod_is_call_and_no_price = ($product_info_metatags->fields['product_is_call'] == '1' && $meta_products_price == 0);
$meta_products_price = (!$prod_is_call_and_no_price ? SECONDARY_SECTION . $currencies->display_price($meta_products_price, zen_get_tax_rate($product_info_metatags->fields['products_tax_class_id'])) : '');
}
} else {
error_log("point 4");
$meta_products_price = SECONDARY_SECTION . META_TAG_PRODUCTS_PRICE_IS_FREE_TEXT;
}
} else {
error_log("point 5");
$meta_products_price = '';
}
is obviously not true.Code:if (zen_check_show_prices() == true) {
In those circumstances, nothing defines $meta_products_price
$meta_products_price also needs to be defined ifis false.Code:zen_check_show_prices()
On the test site, users are required to login to see pricing.
The simple fix required is to add an else to thecheck so that you end up withCode:if (zen_check_show_prices() == true) {
Code:if (META_TAG_INCLUDE_PRICE == '1' and !strstr($_GET['main_page'], 'document_general')) {
if ($product_info_metatags->fields['product_is_free'] != '1') {
if (zen_check_show_prices() == true) {
$meta_products_price = zen_get_products_actual_price($product_info_metatags->fields['products_id']);
$prod_is_call_and_no_price = ($product_info_metatags->fields['product_is_call'] == '1' && $meta_products_price == 0);
$meta_products_price = (!$prod_is_call_and_no_price ? SECONDARY_SECTION . $currencies->display_price($meta_products_price, zen_get_tax_rate($product_info_metatags->fields['products_tax_class_id'])) : '');
} else {
$meta_products_price = '';
}
} else {
$meta_products_price = SECONDARY_SECTION . META_TAG_PRODUCTS_PRICE_IS_FREE_TEXT;
}
} else {
$meta_products_price = '';
}
Er, the bit that you missed in the first code block you posted is highlighted below (that's line 264 that I referenced above):
Code:
} else {
$meta_products_price = '';
// build un-customized meta tag
if (META_TAG_INCLUDE_PRICE == '1' and !strstr($_GET['main_page'], 'document_general')) {
if ($product_info_metatags->fields['product_is_free'] != '1') {
if (zen_check_show_prices() == true) {
$meta_products_price = zen_get_products_actual_price($product_info_metatags->fields['products_id']);
$prod_is_call_and_no_price = ($product_info_metatags->fields['product_is_call'] == '1' && $meta_products_price == 0);
$meta_products_price = (!$prod_is_call_and_no_price ? SECONDARY_SECTION . $currencies->display_price($meta_products_price, zen_get_tax_rate($product_info_metatags->fields['products_tax_class_id'])) : '');
}
} else {
$meta_products_price = SECONDARY_SECTION . META_TAG_PRODUCTS_PRICE_IS_FREE_TEXT;
}
}
if (META_TAG_INCLUDE_MODEL == '1' && !empty($product_info_metatags->fields['products_model'])) {
$meta_products_name = $product_info_metatags->fields['products_name'] . ' [' . $product_info_metatags->fields['products_model'] . ']';
} else {
$meta_products_name = $product_info_metatags->fields['products_name'];
}
$meta_products_name = zen_clean_html($meta_products_name);
$meta_products_description = zen_truncate_paragraph(strip_tags(stripslashes($product_info_metatags->fields['products_description'])), MAX_META_TAG_DESCRIPTION_LENGTH);
$meta_products_description = zen_clean_html($meta_products_description);
define('META_TAG_TITLE', str_replace('"','',$review_on . $meta_products_name . $meta_products_price . PRIMARY_SECTION . TITLE . TAGLINE));
define('META_TAG_DESCRIPTION', str_replace('"','',TITLE . ' ' . $meta_products_name . SECONDARY_SECTION . $meta_products_description . ' '));
define('META_TAG_KEYWORDS', str_replace('"','',$meta_products_name . METATAGS_DIVIDER . KEYWORDS));
} // CUSTOM META TAGS