【问题标题】:How to add custom settings to a Magento Product Meta Page?如何将自定义设置添加到 Magento 产品元页面?
【发布时间】:2013-06-04 00:19:06
【问题描述】:

我是 Magento 的新手,今天才开始使用它。我需要在产品的元选项卡下的管理面板中添加一个自定义选项。我需要添加一个选项,管理员可以选择从 Generated sitemap.xml 文件中删除此产品。

在 wordpress 中,这将通过自定义元字段或自定义设置字段来实现。

Magento 中是否存在类似的功能来设置自定义设置然后检索它们?我看到了一些关于自定义属性的东西,但似乎它们实际上出现在主题和面板中,而不是按照我描述的方式工作?

用户Jürgen Thelen 在下面发布了一个非常有用的sn-p,它可以帮助实际站点地图不包括部分。

所以我只需要弄清楚

  1. 如何将设置添加到产品的元选项卡
  2. 如何在下面的代码中检索此设置值以便我可以使用它

第二部分应该相当简单,创建一个函数来获取所有设置为隐藏在 sitemap.xml 中的产品值,然后在下面的代码中使用它们。

我的主要问题是将设置添加到产品管理页面的元信息区域,有什么帮助吗?

public function getCollection($storeId)
{
    $products = array();

    $store = Mage::app()->getStore($storeId);
    /* @var $store Mage_Core_Model_Store */

    if (!$store) {
        return false;
    }

    $urCondions = array(
        'e.entity_id=ur.product_id',
        'ur.category_id IS NULL',
        $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()),
        $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1),
    );
    $this->_select = $this->_getWriteAdapter()->select()
        ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName()))
        ->join(
            array('w' => $this->getTable('catalog/product_website')),
            'e.entity_id=w.product_id',
            array()
        )
        ->where('w.website_id=?', $store->getWebsiteId())
        // --- exclude single product by its entity_id
        ->where('e.entity_id<>152')
        // --- exclude multiple products by their entity_id's
        // ->where('e.entity_id NOT IN (?)', array(152, 156))
        ->joinLeft(
            array('ur' => $this->getTable('core/url_rewrite')),
            join(' AND ', $urCondions),
            array('url' => 'request_path')
        );

    $this->_addFilter($storeId, 'visibility', Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds(), 'in');
    $this->_addFilter($storeId, 'status', Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(), 'in');

    $query = $this->_getWriteAdapter()->query($this->_select);
    while ($row = $query->fetch()) {
        $product = $this->_prepareProduct($row);
        $products[$product->getId()] = $product;
    }

    return $products;
}

【问题讨论】:

    标签: magento magento-1.7


    【解决方案1】:
    1. 让自己熟悉在 magento (product attributes) 中如何处理产品属性。要将您的元字段添加到产品中,您需要先create an attribute。然后需要将此属性分配给您产品的属性集 (Adding attributes to attributesets)。默认属性集就可以了。新字段现在将显示在您的产品配置中。

    2. 要访问您的新属性,您可以在产品对象上调用 $product-&gt;getData('your_attribute')$product-&gt;getYourAttribute()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2014-07-12
      • 1970-01-01
      相关资源
      最近更新 更多