Magento 2 – Where PRODUCT_HAS_WEIGHT Attribute is Stored

attributesdatabasemagento-2.1product

For some of our configured products (unfortunately), the PRODUCT_HAS_WEIGHT attribute has not been set to 1. Although, the products all have weight set (as a float), Magento still refuses to provide shipping calculation for these products.

I want to modify the PRODUCT_HAS_WEIGHT property for all products in the database. For that I want to access the MySQL database and issue a query that updates all the corresponding fields. Unfortunately, I was unsuccessful in identifying the attribute to update.

For example, to examine the weights, I would do the following:

  1. USE database
  2. SELECT * FROM eav_attribute where attribute_code LIKE '%weight%'
  3. SELECT * FROM catalog_product_entity_decimal where attribute_id = 82

In a similar fashion as in line (2), product has weight is not found.

I'd kindly ask the community, to help me find the related attribute to update for each product.

I'm using Magento CE 2.1.6.

Best Answer

The attribute is not stored, is only use for meta purposes by the repo and it is basically a wrapper for the weight attribute within the method customizeWeightField() of class Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Modifying the product_has_weight you will change the product type; it defaults to 'Virtual' but it will get converted to "Download" if it has downloadable data, remember that 'has' is a magic method prefix, although hasWeight is overridden on product types virtual and downloadable for the purpose of locking down a false Boolean value. The value is not specifically stored, the state will remain in the form of the product type, see the TypeTransitionManager class and the plugin Magento\Downloadable\Model\Product\TypeTransitionManager\Plugin\Downloadable, on configurable products it will be determined by the sum of the children state specified by the meta modifier.