Size SKU in Magento
How can I allow SKU be longer than 34 cha开发者_如何学Pythonracters (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
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.
@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.
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).
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
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
精彩评论