更改Magento产品的属性集。

6

我想修改Magento的属性集。我查阅了相关资料,大家都建议先删除该产品,然后用新的属性集重新导入。

我也这样做了,但是在导入数据后,我发现无法看到与产品相关的产品评论和博客文章。

请问有人能告诉我,在使用新的属性集重新导入产品后,是否可能获取相关的产品评论和博客文章呢?

6个回答

12

一旦设置了产品的属性集,就无法更改。但是使用此模块可以实现更改,因此您不必重新导入数据。

编辑:该模块已不再在Magento Marketplace网站上提供。请查看GitHub页面:https://github.com/flagbit/Magento-ChangeAttributeSet


3
哦我的天,Magento,说真的。你已经存在了多少年,还会做出这样笨重的东西。 - ahnbizcad

5

您也可以直接在数据库中更改属性集。

  • eav_attribute_set表中查找属性集ID。
  • 更改catalog_product_entity中的属性集ID。

当然,在使用此方法更改数据时要小心。


这会带来哪些连锁反应?在引用它的EAV属性表中,例如varchar,ID是否也必须更改? - scrowler
catalog_product_entity 表中 entity_id 为 15 和 14 的产品的 attribute_set_id 更新为 9。这段代码的问题在哪里?当只有一个ID时,它可以正常工作,但是当添加多个ID时,它无法更新。 - Gem
不应该 = 用 in(15,14) 替换 - Boss Nass

2
这个操作有点麻烦而且有些凌乱:
  • 确保新属性集已设置
  • 导出您想要更改的产品
  • 在网站上删除正在更改的产品
  • 更改下载文件中的属性集
  • 重新导入已更改的文件
  • 打开每个更改后的产品,设置其属性值并保存
或者像我这样做,安装Amasty的这个扩展http://amasty.com/mass-product-actions.html - 它使更改变得轻松,并提供了许多节省时间和增强选项。

1

一旦您删除产品,就无法获取旧的评论。

您不需要删除产品。您可以通过编辑和使用更改属性集。 否则,创建新的属性集并创建新产品。


0

可以的。我们可以通过编程方式更改产品属性集。 我更喜欢在目录产品网格中创建批量操作以多选产品,然后为这些产品选择批量操作。

在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());
}

0
您可以在数据补丁应用函数中添加类似以下的内容:
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;
}

这将把制造商产品属性更改为默认属性集。(默认情况下,此属性没有属性集。)希望能有所帮助 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接