I'm trying to set up a form in an external that will give me all Sku's of configurable or simple products in a category entered by the user. Instead, I'm ending up with a list of all products in the store, so my filter doesn't seem to be working:


function getProductSkus(){
        $categoryId = $_POST['categoryId'];
        $productType = $_POST['productType'];
        $category = Mage::getModel('catalog/category')->load($categoryId);
            $productList = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToFilter('type_id', $productType)
            foreach($productList as $product){
                echo $product->getName() . "<br>";


<form action="getproducts.php" method="post">
<p>Category ID: <input name="categoryId" type="text" /></p>
<p>Product Type: <select name="productType">
    <option value="configurable">Configurable</option>
    <option value="simple">Simple</options>
<p><input type="submit" name="submit" value="Submit" /></p>
<?php getProductSkus(); ?>

Can anyone tell me what I'm doing wrong here? I'm essentially following the method here, but using load() after the category filter doesn't seem to have any effect:


I've also used the prepareProductCollection method here with the same results:



I found the problem. It turns out that the current store has to be set where I currently have the app initialized at Mage::app();.

| improve this answer | |

I think Below code solve your concern

$collection = Mage::getModel('catalog/category')
 foreach($collection as $product){
    echo $product->getSku();
| improve this answer | |
  • Using mysql how can i get Product sku, name by selected category id? @Murtuza Zabuawala – Gem Dec 9 '19 at 7:39

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.