Magento: Filter products by Status

后端 未结 5 1887
余生分开走
余生分开走 2020-12-30 00:09

I\'m having some serious Magento issues here. As expected the following:

$products = Mage::getModel(\'catalog/category\')->load($category_id)
->getProd         


        
相关标签:
5条回答
  • 2020-12-30 00:15

    I haven't found an answer as such to my question above. But I have saved a lot of time by using a different method.

    I exported a CSV of all the products in my Magento, deleted all columns except Category ID and SKU (this is all I needed), and then filtered that to return all the skus instead.

    If it helps anyone here is the code -

    <?php
    $file  = fopen('allprods.csv', 'r');
    
    // You can use an array to store your search ids, makes things more flexible.
    // Supports any number of search ids.
    $id = array($_GET['id']);    
    // Make the search ids safe to use in regex (escapes special characters)
    $id = array_map('preg_quote', $id);
    // The argument becomes '/id/i', which means 'id, case-insensitive'
    $regex = '/'.implode('|', $id).'/i';
    
    $skus = array();
    while (($line = fgetcsv($file)) !== FALSE) {  
        list($ids, $sku) = $line;
    
        if(preg_match($regex, $ids)) {
            $skus[] = $sku;
        }
    }
    
    $count = count($skus);
    $i = 1;
    
    echo $category_id;
    foreach ($skus as $sku){
        echo $sku;
        if($i != $count) { echo "`"; }
        $i++;
    }
    

    This solution was created by using a previous topic about filtering CSVs, here

    So for now, I can survive. however - an answer to this question is still needed!

    0 讨论(0)
  • 2020-12-30 00:17

    Don't worry, you simply got trapped by a very unusual constant definition^^. Just try:

    $products = Mage::getModel('catalog/category')->load($category_id)
    ->getProductCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter(
        'status',
        array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
    );
    

    For whatever reasons Varien decided to define this STATUS_DISABLED constant with a value of 2, instead of the more intuitive (and commonly used) value of 0.

    0 讨论(0)
  • 2020-12-30 00:18

    I think you can do this by setting store to default like

    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    

    make sure you save the current store value and set it back after doing the above.

    Or by using a script from outside magento and invoke mage by

    require_once '../app/Mage.php';
    $app = Mage::app();
    Mage::register('isSecureArea', true);
    
    0 讨论(0)
  • Nothing works if catalog_flat_product is on in backend configuration->catalog.

    try this..this will give all the products enabled and disabled ultimately

    $collection = Mage::getResourceModel('catalog/product_collection'); //this will give you all products
    foreach($collection as $col)
    {
    $var = Mage::getModel('catalog/product')->loadByAttribute('sku',$col->getSku());
    echo"<pre>";print_r($var->getData());echo"</pre>";
    }
    

    its really simple and after this you can easily filter products by status

    0 讨论(0)
  • 2020-12-30 00:29
    $products = Mage::getModel('catalog/category')->load($category_id)
            ->getProductCollection()
            ->addAttributeToSelect('*') 
            ->addAttributeToFilter('status', 1) 
            ->addAttributeToFilter('visibility', 4) 
            ->setOrder('price', 'ASC'); 
    
    0 讨论(0)
提交回复
热议问题