2

I have looked and tried for days, so I am going to try asking here. I need to scan a barcode and through that, get a product from the magento store. I have been trying to use these to get some results but no luck.

$collection = Mage::getModel('module/model_name')->getCollection()
$collection = Mage::getModel('catalog/category')->load($categoryId)

I can get Id through the SKU, but that's about it. Can anyone help me with this issue? I would appreciate your help very much.

If this is not possible, would it be possible to make a custom attribute like the sku? (Super attribute or what they are called). So I would be able to get it like the sku?

This is what I ended up doing:

$scannerData = $_REQUEST["q"]; //The scanned data

$catId = 2; //Categori id - 2 is root

$categories = new Mage_Catalog_Model_Category();

$categories->load($catId);

$collection = $categories->getProductCollection()->addAttributeToSelect('ean') ->addAttributeToFilter('ean', $scannerData);

foreach ($collection as $product){

$product_id = $product->getId();
$_product = Mage::getModel('catalog/product')->load($product_id);
}

//Do whatever with the product here

1

It is a good idea to have a static attribute (added to catalog_product_entity) so you can put an index on it.

Beside this it should be easily possible to use:

Mage::getModel('catalog/product')->load('barcode_attribute_name', $scannedBarcode)

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.