我想将可配置产品的所有子项设置为“单独不可见”,并且网站下的复选框也为可配置产品的子项激活。
有没有办法做到这一点?
如果您没有 MySQL 访问权限,我相信这也可以:
$sites=Mage::app()->getWebsites(true);
foreach($sites as $site){
$site_list[]=$site->getWebsiteId();
}
$products=Mage::getResourceModel("catalog/product_collection")->addAttributeToFilter("type_id","configurable");
foreach ($products as $product){
$child_products = $product->getTypeInstance()->getAssociatedProducts();
$child_product_ids=array();
foreach($child_products as $child_product){
array_push($child_product_ids,$child_product->getId());
}
Mage::getSingleton('catalog/product_action')->updateAttributes(
$child_product_ids,
array(
'visibility' => "1",
'website_ids' => $site_list
),
Mage::app()->getStore()->getId()
);
}
如果您可以直接访问 mysql,则可以执行以下操作:
来自可配置子项和父项的关系存储在其中,catalog_product_super_link
因此此表中的所有产品都很简单,它们都是配置的子项。
可见性存储为整数,“单独不可见”的表示为“1”
现在我们可以使用此查询,但是如果您有本地或暂存系统,请先尝试一下!
UPDATE catalog_product_entity_int AS pei
JOIN
catalog_product_super_link AS sl ON pei.entity_id = sl.product_id
JOIN
eav_attribute AS e ON e.attribute_code = 'visibility'
AND pei.attribute_id = e.attribute_id
SET
pei.value = 1
对于网站复选框,请使用此插入选择语句并将{the website id}替换为您的 id
INSERT IGNORE INTO
catalog_product_website (product_id, website_id)
SELECT product_id, {the website id} AS website_id FROM catalog_product_super_link;