Magento mass-assign products to category

前端 未结 4 1632
忘了有多久
忘了有多久 2021-01-14 06:58

As the title says,i need to mass-assign products to a category and from the admin i can only edit one product at a time; i dont know why it just doesnt work to mass add them

4条回答
  •  余生分开走
    2021-01-14 07:47

    You may as well do this using the magento API This is the script I use for mass adding products. sku.txt contains one sku per line.

    login('apiuser', 'apipasswd');
    
    
    $listOfDiscountedSKUFile = "sku.txt";
    
    
    function readinFile($filePath)
    {
        $fp = fopen($filePath,'r') or exit("Unable to open file!");
        $dataItems = array();
        while(!feof($fp))
        {
            $dataItems[] = trim(fgets($fp));
        }
        fclose($fp);
        var_dump($dataItems);
        return $dataItems;
    }
    
    function addToCategory($sku,$categoryId)
    {
        global $proxy,$sessionId;
        $proxy->call($sessionId, 'category.assignProduct', array($categoryId, $sku));
    }
    
    function IsNullOrEmptyString($question){
            return (!isset($question) || trim($question)==='');
    }
    $categoryId = 82;//e.g.
    $listOfSKU = readinFile($listOfDiscountedSKUFile);
    foreach($listOfSKU as $sku)
    {
        addToCategory($sku,$category);
    }
    
    ?>
    

提交回复
热议问题