doublesecretagency / craft-adwizard

Ad Wizard plugin for Craft CMS
Other
7 stars 8 forks source link

Ad without image causes php error in front #2

Closed stevenvandemoortele closed 5 years ago

stevenvandemoortele commented 6 years ago

The Image field has the following label: If no graphic is associated, the ad will not be displayed.

But an ad without a graphic gives the following error: Argument 1 passed to craft\services\Assets::getAssetById() must be of the type integer, null given, called in /vendor/doublesecretagency/craft-adwizard/src/services/Ads.php on line 156

stevenvandemoortele commented 6 years ago

I was getting my ads using an element criteria model: {% set ad1 = craft.adWizard.ads.group('right').orderBy('RAND()').limit(1).one() %}

Resolved my issue by changing it to the following: {% set ad1 = craft.adWizard.ads.group('right').where(['!=', 'assetId', '']).orderBy('RAND()').limit(1).one() %}

lindseydiloreto commented 5 years ago

Fixed this bug. Thanks for reporting it!

In the upcoming v2.1, it will now render normally, and just log an error in the console instead of crashing everything.