Zen Cart Observers: Observations

 plugins, v1.5.3, v1.5.4, v1.5.5, zen-cart  Comments Off on Zen Cart Observers: Observations
Oct 082017

One thing to consider when you’re writing a Zen Cart plugin that includes an observer-class module is the point at which any monitored notification is going to be “fired”.  Auto-loading observers, previously discussed here, are great since using that method can reduce the number of files that a plugin needs in its distribution … but there’s a potential downside (isn’t there always?).

All auto-loading observers are loaded at breakpoint 175 during the Zen Cart autoload process.  That processing loads all files present in the /includes/classes/observers directory whose names match auto.*.php and, if the class’ name adheres to the auto-loading “rules”, creates an instance of the associated class.

If the notifications that your plugin is observing are issued prior to breakpoint 175, then auto-loading isn’t for you!

For example, let’s say that your plugin is monitoring NOTIFIER_CART_ADD_CART_START, issued by the shopping-cart class at the beginning of an add-to-cart action.  Those cart-manipulation actions occur during init_cart_handler.php‘s processing at breakpoint 140, so an auto-loading observer will never see that notification.  Your plugin will need to include an additional file (in /includes/auto_loaders)  to instruct Zen Cart the point at which your observer should be loaded (prior to 140!) and instantiated and its observer-class file’s name must not start with “auto.“.

In summary, while auto-loading observers can simplify a plugin’s distribution, plugin authors need to ensure that auto-loading is compatible with the plugin’s expected functionality.

Zen Cart Rule #1: Shipping Module Names

 hints, php, troubleshoot, zen-cart  Comments Off on Zen Cart Rule #1: Shipping Module Names
Aug 282015

There are rules everywhere.  In the kitchen, my #1 rule is “Never try to catch a falling knife“; it apparently applies to investments, too!  In Zen Cart, my current #1 rule (having spent an inordinate amount of time debugging its misuse) is “Never use an underscore (_) in a shipping module’s name“.

A shipping module (unlike a payment or order-total module) can have multiple methods that it supports, so the built-in Zen Cart processing uses an underscore (_) to record both the Shipping Module and Shipping Method chosen for an order as a single string value.  For example, using Zen Cart v1.5.4, the Store Pickup shipping module supports multiple stores.  When the customer chooses the first store location, the id associated to the shipping selection is storepickup_storepickup0.

Once the shipping selection is made, the Zen Cart processing maps that selection back to the Store Pickup module (storepickup.php) and its storepickup0 method by splitting (via the PHP explode function) that id value at the (presumed single) underscore.  If there’s an underscore in the shipping module’s name, the association between the shipping module and selected method can never be resolved so the customer is always redirected back to the checkout_shipping page (with no message).

Repeat after me:  I will never (again) use an underscore in a shipping module’s name.

Drop-down Attributes Stop Working After Installing AIS

 plugins, troubleshoot, zen-cart  Comments Off on Drop-down Attributes Stop Working After Installing AIS
Mar 152015

If your normal drop-down (a.k.a select-type) attributes stop working after installing my Attribute Image Swatch plugin, then your site’s been the victim of an improperly-coded plugin’s installation SQL script.  This issue has been “known” for a couple of years, with swguy posting this in April of 2012.

I’ll be updating AIS real-soon-now to pro-actively re-insert the missing configuration items if they are not found in your store’s database.  The base Zen Cart install started, as of ZC 1.5.3, creating the problematic configuration items as hidden items within the “Modules” configuration group to circumvent problems in the future.

Update (2015-03-16): Attribute Image Swatch v1.1.4 has been released, including the above change.