Size SKU in Magento

♀尐吖头ヾ 提交于 2021-02-19 05:40:08

问题


How can I allow SKU be longer than 34 characters (for simple products) for all products?

When i add new product(simple) and enter more than 34 characters, Magento cuts it to 34 after saving.

In the database the 'sku' attributes ( for quete item,order item,invoice item, shipment item) from eav_attribute table hold varchar(255). For Catalog_Product_Entity the attributed is VarChar(64). In either case, it is more than 34characters. Thus, I could change SKU to 64 characters without making any change in database, correct?

How do i do that? I have good understanding of the user side magento code, but not Admin side. Can you suggest me good tutorial on making changes in Admin side that could help me figure this question myself.

Thank you, Margots


回答1:


@latvian The kind of modification that you propose as a solution is not a very good idea as it breaks compatibility with the core installation and it may create unpredicted behaviour in the future when upgrading the core. This quick and dirty way of solving problems will only create problems in the future.

What I recommend is adding a custom attribute to the product object called custom_sku that can be a string and you can make it as long as you want. Here is a link on how to add a custom attribute to your installation.




回答2:


There's more to it than this even....

Change SKU field in: catalog_product_entity to varchar(255) Change SKU field in: catalog_product_flat_some_number to varchar(255)

And then you will have to edit the Sku.php so the validation wont trigger in the admin.

Change: const SKU_MAX_LENGTH = 64;

to: const SKU_MAX_LENGTH = 255;

That will allow the max_length to be 255 instead of 64.. make it whatever you'd like.




回答3:


I got this myself. Here is what I did.

First,I made mistake on counting in the above. By default Magento lets SKU# be 64 max long. This is because the shortest of the SKU attributes( in table catalog_product_entity) in the DB is set to varchar(64).

  1. Change SKU attribute in catalog_product_entity table to varchar(255) or any length you want. If this length is less than 255 you are fine otherwise you have to change other SKU attributes such as Order SKU, Quote SKu and other in the DB

  2. By setting the SKU length too large it breaks the grid in the Catalog->Product Manage. One solutions is to insert following code in /design/adminhtml/default/default/template/widget/grid.phtml line 157 (after this line: <?php foreach ($this->getCollection() as $_index=>$_item): ?>)

    <?php //truncates SKU when too large
    $sku = $_item->getData('sku');
    if(strlen($sku)>60){
        $sku = substr($sku,0,60);
    }
    $_item->setData('sku',$sku);
    ?>
    

Now even though you will not be able to see the full SKU number in Catalog->Product Manage, you will see full SKU when double click/edit the product individually.

I hope it was useful.

Best



来源:https://stackoverflow.com/questions/2089370/size-sku-in-magento

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!