1

I'm on Craft 3.4.30 (latest 3.4) and Commerce 2.2.25 (latest 2.2):

My product type "ticket" has a custom date field with handle productStartDate.

E.g. the following query in TWIG works:

{% set products = craft.products().type('ticket').productStartDate('>= 2021-01-01 00:00:00').all() %}

I get nice results including my custom field productStartDate

I am trying the same in a console command with PHP:

use craft\commerce\elements\Product;
$product = Product::find()
                ->type('ticket')
                ->productStartDate('>= 2021-01-01 00:00:00')
                ->all();

Gives me this Exception:

Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: craft\behaviors\CustomFieldBehavior::productStartDate()'

in /myproject/vendor/yiisoft/yii2/base/BaseObject.php:222

Stack trace:
#0 /myproject/storage/runtime/compiled_classes/CustomFieldBehavior.php(542): yii\base\BaseObject->__call('productStartDat...', Array)
#1 [internal function]: craft\behaviors\CustomFieldBehavior->__call('productStartDat...', Array)
#2 /myproject/vendor/yiisoft/yii2/base/Component.php(297): call_user_func_array(Array, Array)
#3 /myproject/vendor/craftcms/cms/src/elements/db/ElementQuery.php(548): yii\base\Component->__call('productStartDat...', Array)
#4 /myproject/modules/console/controllers/WarmProductGroupsController.php(61): craft\elements\db\ElementQuery->__call('productStartDat...', Array)
#5 [internal function]: modules\console\controllers\WarmProductGroupsController->actionIndex(false)
#6 /myproject/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /myproject/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#8 /myproject/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('', Array)
#9 /myproject/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('', Array)
#10 /myproject/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('theme/warm-prod...', Array)
#11 /myproject/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('theme/warm-prod...', Array)
#12 /myproject/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('theme/warm-prod...', Array)
#13 /myproject/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#14 /myproject/craft(22): yii\base\Application->run()
#15 {main}

Any hints why?

1

Found it: the reason for the Exception is, that the dynamic method productStartDate (coming from the CustomFieldBehavior) needs an Array as parameter.

I have no clue why I get this misleading Exception though...

So finally, this works:

use craft\commerce\elements\Product;
$product = Product::find()
                ->type('ticket')
                ->productStartDate(['>="2021-01-01 00:00:00"'])
                ->all();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.