Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined property error when loading/saving variants with descriptionFormat #1333

Closed
kswilliames opened this issue Mar 23, 2020 · 6 comments
Labels
ℹ️ status: need more info When waiting for user to supply database or more information.

Comments

@kswilliames
Copy link

kswilliames commented Mar 23, 2020

Description

Commerce throws an undefined property error when getting or saving products where the product type has descriptionFormat set.

This is preventing us from displaying legible descriptions on line-items for our invoices.

Example of descriptionFormat:

{product.title} - {title}

Steps to reproduce

  1. Create a new product with a title
  2. Create a variant for that product with a title and descriptionFormat
  3. Attempt to load or save a product of that type

Error:

error: Undefined property: craft\commerce\elements\Variant::$description

Additional info

  • Craft version: Craft Pro 3.4.9
  • PHP version: 7.4.2
  • Database driver & version: MySQL 5.7.29
  • Plugins & versions:

image

@kswilliames
Copy link
Author

Here is the stack trace:

Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php(74): yii\base\ErrorHandler->handleError(8, 'Undefined prope...', '/var/www/html/v...', 126)
#1 /var/www/html/vendor/yiisoft/yii2/base/ArrayableTrait.php(126): craft\web\ErrorHandler->handleError(8, 'Undefined prope...', '/var/www/html/v...', 126, Array)
#2 /var/www/html/vendor/craftcms/cms/src/web/View.php(636): yii\base\Model->toArray(Array, Array, false)
#3 /var/www/html/vendor/craftcms/commerce/src/elements/Variant.php(408): craft\web\View->renderObjectTemplate('{{ (_variables....', Object(craft\commerce\elements\Variant))
#4 /var/www/html/vendor/yiisoft/yii2/base/Component.php(139): craft\commerce\elements\Variant->getDescription()
#5 /var/www/html/vendor/craftcms/cms/src/base/Element.php(1102): yii\base\Component->__get('description')
#6 /var/www/html/vendor/yiisoft/yii2/validators/Validator.php(254): craft\base\Element->__get('description')
#7 /var/www/html/vendor/yiisoft/yii2/base/Model.php(367): yii\validators\Validator->validateAttributes(Object(craft\commerce\elements\Variant), Array)
#8 /var/www/html/vendor/yiisoft/yii2/base/Model.php(936): yii\base\Model->validate(Array)
#9 /var/www/html/vendor/craftcms/commerce/src/elements/Product.php(853): yii\base\Model::validateMultiple(Array)
#10 /var/www/html/vendor/yiisoft/yii2/base/Model.php(369): craft\commerce\elements\Product->afterValidate()
#11 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1988): yii\base\Model->validate()
#12 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(530): craft\services\Elements->_saveElementInternal(Object(craft\commerce\elements\Product), true, false, NULL)
#13 /var/www/html/vendor/craftcms/commerce/src/controllers/ProductsController.php(225): craft\services\Elements->saveElement(Object(craft\commerce\elements\Product))
#14 [internal function]: craft\commerce\controllers\ProductsController->actionSaveProduct()
#15 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#17 /var/www/html/vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction('save-product', Array)
#18 /var/www/html/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-product', Array)
#19 /var/www/html/vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction('commerce/produc...', Array)
#20 /var/www/html/vendor/craftcms/cms/src/web/Application.php(559): craft\web\Application->runAction('commerce/produc...', Array)
#21 /var/www/html/vendor/craftcms/cms/src/web/Application.php(270): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#22 /var/www/html/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#23 /var/www/html/web/index.php(33): yii\base\Application->run()
#24 {main}```

@kswilliames
Copy link
Author

kswilliames commented Mar 23, 2020

Appears to be an issue with Craft::$app->getView()->renderObjectTemplate($format, $this) not rendering the title correctly in craft\commerce\elements\Variant:408

@nfourtythree
Copy link
Contributor

Hi @kswilliames

I can't seem to replicate this issue locally. I have put together a video showing the steps I went through https://x.n43.me/P8uRDqmE

It seems like something else might be at play here. Could you send your composer.json, composer.lock and a DB dump to support@craftcms.com

This way we can try and identify what is going on.

Thanks.

@nfourtythree nfourtythree added the ℹ️ status: need more info When waiting for user to supply database or more information. label Mar 23, 2020
@kswilliames
Copy link
Author

Hi @nfourtythree

Thanks for getting back so quickly. Here's the error I'm getting.

image

I found a workaround for it, and a more accurate way to replicate the problem. We have a product variant custom field called description. When removing or renaming this field, the product will save and correctly generate the order description.

Steps to reproduce

  1. Create a new product type
  2. Create a new custom field with handle set to description
  3. Add the new custom field to Variant Fields in the new product type
  4. Create a new product under that product type with a title
  5. Create a variant for that product with a title and descriptionFormat {product.title} - {title}
  6. Attempt to load or save a product of that type

Workaround

  1. Remove the custom field called description
    or
  2. Rename the custom field called description

@lukeholder
Copy link
Member

description is a reserved handle, since it is used in the purchasable interface. We should make that more clear in the docs and CP validation when saving the variant field layout.

@lukeholder
Copy link
Member

Related craftcms/cms#918

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ℹ️ status: need more info When waiting for user to supply database or more information.
Projects
None yet
Development

No branches or pull requests

3 participants