我正在为这样的产品插入类别。
$designer=$_POST['design']; $product->setCategoryIds(array($designer));
在 PHP 代码中,您可以在导入它们时将它们放入类别中。假设您有一个名为 $product 的产品和一个名为 $category_id 的类别 ID 您可以通过执行以下代码将其放入一个类别中
$product->setCategoryIds(array($category_id));
$product->save();
使用如下:
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
// Load products
$products = Mage::getModel('catalog/product')
->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)
->getAll();
// Load categories
$category = Mage::getModel('catalog/category');
->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID);
$categories = $category->getAll();
foreach($products as $product) {
// Get relevant category
$product->setCategoryIds(array($category->getId()));
$product->save();
}
您可能需要对上述代码进行一些调整,以使其符合您的需要。