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

InvalidArgumentException: Options must be an array. #897

Closed
hegrobler opened this issue Jun 10, 2019 · 5 comments
Closed

InvalidArgumentException: Options must be an array. #897

hegrobler opened this issue Jun 10, 2019 · 5 comments
Labels
ℹ️ status: need more info When waiting for user to supply database or more information.

Comments

@hegrobler
Copy link

Description

I upgraded from Craft 2 & Commerce 1 to Craft 3 & Commerce 2. Everything seemed to be going well, but as I started working through the eCommerce templates to fix the deprecation errors, I started running into the following error:
[error][Twig\Error\RuntimeError] yii\base\InvalidArgumentException: Options must be an array. in /usr/home/abcdefg/craft/vendor/craftcms/commerce/src/models/LineItem.php:193

This error is displayed whenever I attempt to list orders using the following template code:

{% set orders = craft.orders.customer(craft.commerce.customers.customer).isCompleted(true).all() %} {% if orders | length %} {% for order in orders %} ........ {% endfor %} {% endif %}
I also receive the error when attempting to browse the order listing in the Cpanel

Steps to reproduce

  1. Login as admin
  2. From the left hand nav click on Commerce > Orders > Processing
  3. "An unknown error has occured" is briefly displayed & checking the log file shows:
    [error][Twig\Error\RuntimeError] yii\base\InvalidArgumentException: Options must be an array. in /usr/home/abcdefg/craft/vendor/craftcms/commerce/src/models/LineItem.php:193

-- Alternatively ---

  1. Login as a user who has existing orders
  2. Browse to shop/customer of the sample templates
  3. Same error occurs

Additional info

  • Craft version: 3.1.29
  • PHP version: 7.2
  • Database driver & version: MySQL 5.5.5
  • Plugins & versions:
    Calendar 2.0.20
    Craft Commerce 2.1.6.1
    Imager v2.1.10
    Redactor 2.3.3.2
    Site Switcher 2.1.0
@hegrobler
Copy link
Author

I've narrowed this done some more - the error specifically occurs when using {{ order.totalPrice }} in a template eg:
{% set orders = craft.orders.customer(craft.commerce.customers.customer).isCompleted(true).all() %}
{% if orders | length %}
{% for order in orders %}
{{ order.totalPrice }}
{% endfor %}
{% endif %}

@hegrobler
Copy link
Author

This error is now occurring when I try to update a user who has Commerce transactions in the cPanel. It prevents me from being able to do any updates to the user

2019-06-17 12:10:13 [-][6580][7123a3492071e65e1112aca1397f732d][profile end][yii\db\Command::query] SELECT id, options, price, saleAmount, salePrice, weight, length, height, width, qty, snapshot, note, purchasableId, orderId, taxCategoryId, shippingCategoryIdFROMcraft_commerce_lineitems lineItemsWHEREorderId=10497 2019-06-17 12:10:13 [-][6580][7123a3492071e65e1112aca1397f732d][trace][yii\db\Transaction::rollBack] Roll back transaction 2019-06-17 12:10:13 [-][6580][7123a3492071e65e1112aca1397f732d][error][yii\base\InvalidArgumentException] yii\base\InvalidArgumentException: Options must be an array. in /usr/home/devitvktxz/craft/vendor/craftcms/commerce/src/models/LineItem.php:195 Stack trace: #0 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/Component.php(180): craft\commerce\models\LineItem->setOptions(NULL) #1 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/BaseYii.php(546): yii\base\Component->__set('options', NULL) #2 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(craft\commerce\models\LineItem), Array) #3 /usr/home/devitvktxz/craft/vendor/craftcms/commerce/src/services/LineItems.php(106): yii\base\BaseObject->__construct(Array) #4 /usr/home/devitvktxz/craft/vendor/craftcms/commerce/src/elements/Order.php(1267): craft\commerce\services\LineItems->getAllLineItemsByOrderId(10497) #5 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/Component.php(139): craft\commerce\elements\Order->getLineItems() #6 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/base/Element.php(830): yii\base\Component->__get('lineItems') #7 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/validators/Validator.php(254): craft\base\Element->__get('lineItems') #8 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/Model.php(367): yii\validators\Validator->validateAttributes(Object(craft\commerce\elements\Order), Array) #9 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/services/Elements.php(430): yii\base\Model->validate() #10 /usr/home/devitvktxz/craft/vendor/craftcms/commerce/src/services/Customers.php(441): craft\services\Elements->saveElement(Object(craft\commerce\elements\Order)) #11 [internal function]: craft\commerce\services\Customers->saveUserHandler(Object(craft\events\ModelEvent)) #12 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Array, Object(craft\events\ModelEvent)) #13 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\\elements\\...', 'afterSave', Object(craft\events\ModelEvent)) #14 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/base/Element.php(1889): yii\base\Component->trigger('afterSave', Object(craft\events\ModelEvent)) #15 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/elements/User.php(1322): craft\base\Element->afterSave(false) #16 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/services/Elements.php(516): craft\elements\User->afterSave(false) #17 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/controllers/UsersController.php(1089): craft\services\Elements->saveElement(Object(craft\elements\User), false) #18 [internal function]: craft\controllers\UsersController->actionSaveUser() #19 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) #20 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array) #21 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/web/Controller.php(109): yii\base\Controller->runAction('save-user', Array) #22 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-user', Array) #23 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/web/Application.php(297): yii\base\Module->runAction('users/save-user', Array) #24 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/web/Application.php(565): craft\web\Application->runAction('users/save-user', Array) #25 /usr/home/devitvktxz/craft/vendor/craftcms/cms/src/web/Application.php(281): craft\web\Application->_processActionRequest(Object(craft\web\Request)) #26 /usr/home/devitvktxz/craft/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request)) #27 /usr/www/users/devitvktxz/index.php(21): yii\base\Application->run()

@lukeholder
Copy link
Member

Can you please send your pre-updated database and post updated database backups to support@craftcms.com and I will take a look.

@lukeholder lukeholder added the ℹ️ status: need more info When waiting for user to supply database or more information. label Jun 17, 2019
@hegrobler
Copy link
Author

Have emailed DBs

@hegrobler
Copy link
Author

Issue does not seem to happen on commerce v.2.1.6.1. I suspect something was introduced in v2.1.7 but dont know enough about the ecosystem to debug in more detail. Maybe a migration did not run correctly?

Function setOptions on Line 188 in craft/vendor/craftcms/commerce/src/models/LineItem.php
expects a json string or an array. I dumped the values being passed as param $options and in my setup is always []. Which means empty json / no options. But in some cases a null is passed in which causes the error. I assume that if a null is passed in it should have actually been a [].

Based on my assumption that null should be [], I added another if to the start of the function which seems to solve the issue for now.

    public function setOptions($options)
    {
        if (empty($options)) {
            $options = [];
        }

        if (is_string($options)) {
            $options = Json::decode($options);
        }

        if (!is_array($options)) {
            throw new InvalidArgumentException('Options must be an array.');
        }

angrybrad pushed a commit that referenced this issue Jun 29, 2019
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

2 participants