verbb / snipcart

A Craft CMS plugin to integrate with Snipcart.
Other
21 stars 9 forks source link

count(): Parameter must be an array or an object that implements Countable #3

Closed piotrpog closed 5 years ago

piotrpog commented 5 years ago

I decided to test your plugin on my local machine. First I set up fresh craft install and installed plugin. Then I ran migrations taken from example project and copied templates from it. When I try to open frontend product page, I get an error:

count(): Parameter must be an array or an object that implements Countable
1. in C:\xampp\htdocs\test8\vendor\workingconcept\craft-snipcart\src\models\ProductDetails.php at line 447   

My system info: PHP version 7.2.2 OS version WINNT 10.0 Database driver & version MySQL 5.5.5 Image driver & version GD 7.2.2 Craft edition & version Craft Solo 3.1.16 Yii version 2.0.16.1 Twig version 2.6.2 Guzzle version 6.3.3 Imagine version 0.7-dev

mattstein commented 5 years ago

Thanks for opening an issue, @piotrpog!

It looks like that might actually be a problem with my example; customOptions should only be able to get an array and my example makes it possible to be null:

{{ productInfo.getBuyNowButton({
    text: 'Buy Now + Options',
    customOptions: formattedOptions ? [{
        name: 'Product Option',
        required: true,
        options: formattedOptions
    }] : null,
    classes: buttonClasses
}) | raw }}

Does it fix the problem if you change null above to []? If not, would you mind sharing the full template for whatever page is throwing the error?

mattstein commented 5 years ago

Nevermind, I can reproduce this with PHP 7.2.14 and Snipcart 1.0.2! Will have a fix shortly.

Edit: For what it's worth, changing raw to [] should also get you moving again in the meantime.

mattstein commented 5 years ago

Just published v1.0.3 @piotrpog, let me know if this does not solve the problem for you!