‘Sorting Product List with Integer Attibutes’… bit of a mouthful ain’t it? There’s a bit of a limitation with Magento’s sort feature when it comes to custom attributes. It will normally sort our text strings alphabetically without a problem, but if your value is an integer Magento will still treat it as a string. This means that your numbers will be about as organised as my suitcase after a holiday:
10010002002200300400Not ideal is it? I’m hoping that Magento will fix this by the next release – it only needs to be an extra attribute option which defines any values as an integer. It is something which could easily be mastered with an extension, but I personally think it’s more of a core requirement. The good news is that there’s a short term solution which works just as well. Simply use the attribute type of ‘Price’ when you’re creating your attribute.

The next issue is that your echoed attributes will show in currency format: 100.00, but the PHP round function will format it nicely for frontend purposes.
$attribute = $_product->getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product);echo round($attribute);Would be nice for Magento if gets this sorted for the next release, in the meantime this will do a job for you. Thanks for reading the Magento Blog at E-commerce Website Design.
Adam Moss Author Page
Không có nhận xét nào:
Đăng nhận xét