Update to 7.x-4.0-beta1.
Enable commerce reports: stock levels broke the site: The website encountered an unexpected error. Please try again later.
-------
Uninstall the module and reinstall it with 7.x-4.0-beta1 two times by following instructions in read me. Still throw out unexpected error.
If disable commerce reports: stock levels, everything run smoothly and the Commerce reports dashboard is accessible (Reports, Tax reports and Geckoboard enabled).

Comments

Salif’s picture

Assigned: Salif » Unassigned
mglaman’s picture

Can you please post error created in the database log?

mglaman’s picture

Priority: Normal » Major

Is your error this:

Notice: Undefined variable: products in _commerce_reports_stock_get_stock_enabled_products() (line 173 of /var/www/commerce_deploy/sites/all/modules/commerce_reports/modules/stock/commerce_reports_stock.module).

Looks like it might be an issue when there are not products with stock. I also noticed that this may be dependent on Commerce Simple Stock (for the default commerce_stock field.)

Salif’s picture

Hi mglaman
I will reproduce by enabling the stock reports feature and then report to you soon.

Salif’s picture

The error is:
EntityFieldQueryException: Unknown field: commerce_stock in EntityFieldQuery->addFieldCondition() (line 779 of .../public_html/includes/entity.inc).

Salif’s picture

Commerce stock was missing (Haven't seen yet a dependancy of Commerce reports on Commerce stock !?)
Enable commerce stock 7.x-2.0 module:
- Enable the Commerce Stock API & Commerce Simple stock modules.
Configured as per instruction:
- Select the “simple stock management” tab,
- - Check the product types for simple stock to manage.
-------------
And now
"The website encountered an unexpected error" gone.
And I can visite all reports tabs: Dasboard, Products, Stock, taxes, Customers, sales & Payment methods
-------------
But now the error you've mentionned above appear in error log messages.

Notice: Undefined variable: products in _commerce_reports_stock_get_stock_enabled_products() (line 173 of /home/savabien/public_html/sites/all/modules/commerce_reports/modules/stock/commerce_reports_stock.module).

Warning: Invalid argument supplied for foreach() in _commerce_reports_stock_get_stock_enabled_products() (line 173 of /home/savabien/public_html/sites/all/modules/commerce_reports/modules/stock/commerce_reports_stock.module).

mglaman’s picture

Do you have Commerce Reports Stock enabled without enabling Commerce Stock? The issue is empty values, apparently. Before it was a silent fail because it didn't use EntityMetadataWrappers, so there wasn't an EntityException.

Just disable Commerce Reports Stock for now, I will have fix up later tonight.

Salif’s picture

Thanks much @ mglaman
Yes I will use the other features that are available and disable the Commerce Reports Stock report for now, as you suggested.
... The error came back when I try to put products (quantity) in stock.

  • mglaman committed 6b9cc2e on 7.x-4.x
    Issue #2334803 by Salif: Fixed commerce reports: stock levels broke the...
mglaman’s picture

Status: Active » Fixed

Thanks for catching this right away for me, and being patient for the fix!

If there were no products with a stock value, this was still being run, event though $products didn't exist, throwing the first error.

      // Key the list by SKU
      // @todo: Is there a way to do this already in core Commerce?
      foreach ($products as $pid => $product) {
        $product_list[$product->sku] = $product;
      }

I updated the stock check to use EntityMetadataWrapper's __isset(). The commerce_stock field is only created via Commerce Simple Stock (commerce_ss) and may not exist on all product types. This checks first.

      // Provide a default value.
      $stock = 0;
      // @todo: This assumes Commerce Simple Stock was utilized.
      if ($product_wrapper->__isset('commerce_stock')) {
        $stock =  (int) $product_wrapper->commerce_stock->value();
      }

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.