soxophoneplayer:
Thanks for answer to previous q.
New question.
Using test site on wamp with zc1.5.5f, IH5, clone of responsive_classic, SbyA 1.54 for zc 1.5.5f, Colorbox 2.1.2. , One Page Checkout most current, wamp php 7.1.13, one category with one product. Product has 4 size attributes with stock. Product info has 4 additional images (not attribute). Size attribute photos installed via attributes controller. All photos are jpg.
Dynamic Dropdowns set to 0 (off)
SbyA config in Stock - Display Attribute images set to 1. (tried setting as on with single attribute option and radio selected)
Attribute Settings - Enable attribute images set to true.
IH5 set to resize images, on. (also tried with set to off)
Option Name controller- Size attribute set to radio, and display option 6 selected with images per row left blank (also tried 1, 4). (also tried display option 7 and 8)
When clicking on the size radio button on the product page the attribute image is not swapping in. Also tried removing the non-attribute additional images from the propduct info page.
The following error gets logged when attempting to select an attribute:
05-Feb-2018 01:08:42 UTC] PHP Fatal error: Uncaught Error: Call to a member function notify() on null in C:\wamp\www\includes\modules\doug_responsive\main_product_image.php:19
Stack trace:
#0 C:\wamp\www\includes\classes\ajax\zcAttrib_prod_info.php(48): require_once()
#1 C:\wamp\www\ajax.php(76): zcAttrib_prod_info->swap_image()
#2 {main}
thrown in C:\wamp\www\includes\modules\doug_responsive\main_product_image.php on line 19
>
> I note that main_prodcut_image.php line 19 is a merged change from IH5. Beyond that, I haven't a clue what the error means ;-)
So the error message above:
05-Feb-2018 01:08:42 UTC] PHP Fatal error: Uncaught Error: Call to a member function notify() on null in C:\wamp\www\includes\modules\doug_responsive\main_product_image.php:19
Stack trace:
#0 C:\wamp\www\includes\classes\ajax\zcAttrib_prod_info.php(48): require_once()
#1 C:\wamp\www\ajax.php(76): zcAttrib_prod_info->swap_image()
#2 {main}
thrown in C:\wamp\www\includes\modules\doug_responsive\main_product_image.php on line 19
is reporting an issue with this line:
$zco_notifier->notify('NOTIFY_MODULES_MAIN_PRODUCT_IMAGE_START');
Specifically saying that member function notify() is being called on an undefined variable. The "undefined" variable is $zco_notifier. In ZC this is defined as a "global" type variable and in "normal" operation (viewing of a product) the main_product_image.php module file is in the global space and therefore $zco_notifier is defined. The way that this module has been put together, that module file is called within a class so that the operations performed by that module do not have to be rewritten and historically have fallen in line with the initial provided data to give a final result. That said, though, IH5 introduced notifiers into the module file, which in design is not a problem, but this module did not previously include all of the ZC defined "global" variables that are possible (not needed, don't include them right?)
So, to resolve this there are two approaches that can be taken. One specifically for this plugin, one that could be done for the modified main_product_file, although the modification suggested for that file would not be historically consistent with other files that are expected to be in the global space.
For this module (or of course any module that was including the main_product_image.php file outside of the global space) look at includes/classes/ajax/zcAttrib_prod_info.php and modify this portion
from:
function swap_image()
{
global $db;
to:
function swap_image()
{
global $db, $zco_notifier;
And that will resolve the issue.
Another supposedly "acceptable" modification would be to define $zco_notifier to be equal to the current class because the current class extends the base class and that means that the current class also has access to the notify member function, so:
function swap_image()
{
global $db;
$products_options_values_id = (int)$_POST['products_options_values_id'];
could become:
function swap_image()
{
global $db;
$zco_notifier = $this;
$products_options_values_id = (int)$_POST['products_options_values_id'];
But then below this point $zco_notifier could be accessed like: $zco_notifier->swap_image() which may not seem right... :P
or it could be rewritten like this:
function swap_image()
{
global $db;
$zco_notifier = $GLOBALS['zco_notifier'];
$products_options_values_id = (int)$_POST['products_options_values_id'];
For the time being, I'd go with the first suggestion. :)
The other alternative suggestion which doesn't exactly go in line with other modules using an notifier would be to modify the includes/modules/YOUR_TEMPLATE/main_product_image.php file from:
// This notifier lets an observer know that the module has begun its processing.
//
$zco_notifier->notify('NOTIFY_MODULES_MAIN_PRODUCT_IMAGE_START');
to:
// This notifier lets an observer know that the module has begun its processing.
//
if (!isset($zco_notifier)) {
global $zco_notifier;
}
$zco_notifier->notify('NOTIFY_MODULES_MAIN_PRODUCT_IMAGE_START');
or similar to bring $zco_notifier into the space of the module. Thing is, generally speaking whatever the module needs to be able to operate, the calling/including/requiring code probably should be sure to provide to it, even if there has been a change in how the module operates/is written. For example if the module did something with money, then likely the $currencies global variable would need to be made available for it to do its business.
Thank you for identifying this issue, I am incorporating the first suggestion above into the file on github as addressed in [issue #2](https://github.com/mc12345678/Attribute_image_Swap/issues/2) and this [commit](https://github.com/mc12345678/Attribute_image_Swap/commit/91a1785acec55ba014c3419578fdb4ad300eb0eb).