我想修改Magento的属性集。我查阅了相关资料,大家都建议先删除该产品,然后用新的属性集重新导入。
我也这样做了,但是在导入数据后,我发现无法看到与产品相关的产品评论和博客文章。
请问有人能告诉我,在使用新的属性集重新导入产品后,是否可能获取相关的产品评论和博客文章呢?
我想修改Magento的属性集。我查阅了相关资料,大家都建议先删除该产品,然后用新的属性集重新导入。
我也这样做了,但是在导入数据后,我发现无法看到与产品相关的产品评论和博客文章。
请问有人能告诉我,在使用新的属性集重新导入产品后,是否可能获取相关的产品评论和博客文章呢?
一旦设置了产品的属性集,就无法更改。但是使用此模块可以实现更改,因此您不必重新导入数据。
编辑:该模块已不再在Magento Marketplace网站上提供。请查看GitHub页面:https://github.com/flagbit/Magento-ChangeAttributeSet
您也可以直接在数据库中更改属性集。
eav_attribute_set
表中查找属性集ID。catalog_product_entity
中的属性集ID。当然,在使用此方法更改数据时要小心。
catalog_product_entity
表中 entity_id
为 15 和 14 的产品的 attribute_set_id
更新为 9。这段代码的问题在哪里?当只有一个ID时,它可以正常工作,但是当添加多个ID时,它无法更新。 - Gem一旦您删除产品,就无法获取旧的评论。
您不需要删除产品。您可以通过编辑和使用更改属性集。 否则,创建新的属性集并创建新产品。
可以的。我们可以通过编程方式更改产品属性集。 我更喜欢在目录产品网格中创建批量操作以多选产品,然后为这些产品选择批量操作。
在grid.php中创建批量操作
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
->load()
->toOptionHash();
$this->getMassactionBlock()->addItem('changeattributeset', array(
'label'=> Mage::helper('catalog')->__('Change attribute set'),
'url' => $block->getUrl('*/*/changeattributeset', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'attribute_set',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('catalog')->__('Attribute Set'),
'values' => $sets
)
)
));
public function changeattributesetAction()
{
$productIds = $this->getRequest()->getParam('product');
$storeId = (int)$this->getRequest()->getParam('store', 0);
if (!is_array($productIds)) {
$this->_getSession()->addError($this->__('Please select product(s)'));
} else {
try {
foreach ($productIds as $productId) {
$product = Mage::getSingleton('catalog/product')
->unsetData()
->setStoreId($storeId)
->load($productId)
->setAttributeSetId($this->getRequest()->getParam('attribute_set'))
->setIsMassupdate(true)
->save();
}
Mage::dispatchEvent('catalog_product_massupdate_after', array('products'=>$productIds));
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) were successfully updated', count($productIds))
);
}
catch (Exception $e) {
$this->_getSession()->addException($e, $e->getMessage());
}
}
$this->_redirect('adminhtml/catalog_product/index/', array());
}
public function apply(): self
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttributeToSet(
Product::ENTITY,
'Default',
'General',
CustomAttributesInterface::ATTRIBUTE_CODE_MANUFACTURER
);
$this->moduleDataSetup->getConnection()->endSetup();
return $this;
}
这将把制造商产品属性更改为默认属性集。(默认情况下,此属性没有属性集。)希望能有所帮助 :)