3

I'm building a custom shipping method for Magento 2. And I couldn't seem to find product dimensions within the standard attributes

However, when receiving product data information from the checkout in my plugin it does show width, height and length. (dump shown below)

{"street":"Test street 23","postcode":"1122AB","country":"NL","city":"Amsterdam","packages":{"height":null,"width":null,"length":null,"qty":1,"value":45,"weight":0}}

As I want to make this shipping method as general as possible, where can these 'standard' attributes for dimensions be set?

Thanks.

  • Height is default attribute. But, width and length do not exist. – Khoa TruongDinh Dec 2 '17 at 22:25
1

It is recommended to add width, length, height attributes to product from admin panel. To create a new attribute login to your website’s admin dashboard and navigate to the Stores>Attributes>Product section of Store

This will open the list of all attributes currently available on store. To create a new one click on the big orange Add New Attribute button.

Now you will be able to configure the attribute. Attribute Code – The name of the attribute that will be used by the system Scope – allows you to declare the attribute value saving scope like Website - the value of this attribute for a product can be different in different Websites but have to stay the same between Store Views contained under the same Website. Store View - the value of this attribute for a product can be different in all Websites and all Store Views Website - the value of this attribute for a product can be different in different Websites but have to stay the same between Store Views contained under the same Website Global - the value of this attribute for a product must be the same for all websites and stores

Unique Value – Set this to Yes, if you want the data saved in this attribute to be unique for each product. If you have different products made of the same material or having the same feature, leave this to No Input Validation for Store Owner – If you want to validate the data before applying changes to the attribute, select Yes Add to Column Options – To add this attribute to the list of column options please select Yes Use in Filter Options – If you set this to Yes the attribute will be added to the list of filter options

From the menu on the left, click on the Storefront Properties tab to configure the frontend behavior of the attribute.

To save your new attribute click on the Save Attribute button on the top right corner of your screen. This will bring you back to the attributes list page on which you should see your new attribute.

For more refer to this short tutorial : https://www.fastcomet.com/tutorials/magento2/product-attributes

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Jai Dec 3 '17 at 2:11
  • yes you have raison – MagentoDeveloper Dec 4 '17 at 8:42
  • This answers how to do it manually, im looking for the already build in height, width and length whose are retrieveable by calling getPackageHeight(), getPackageWidth(), and getPackageWidth() – Dion Dec 13 '17 at 18:52
  • $this->getProduct()->getAttributeText('attribute_text'); e.g: $this->getProduct()->getAttributeText('widht'); – MagentoDeveloper Dec 15 '17 at 8:36
  • or $_product = $block->getProduct(); $attribute_code="description"; // attribute with text value $description_attribute = $_product->getResource()->getAttribute($attribute_code); $description= $description_attribute ->getFrontend()->getValue($_product); – MagentoDeveloper Dec 15 '17 at 8:44
1

These default product dimensions I was looking for, are now available since magento version 2.2.5 and are retrievable like so;

$product->getTsDimensionsLength();
$product->getTsDimensionsWidth();
$product->getTsDimensionsHeight();

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.