3

我有一个简短的问题要问你。Magento 已经有一个用于产品和类别的规范工具。

但这如何与多家商店一起使用?

例子:

我有 3 个域。

http://domainname1.at
http://domainname2.de
http://domainname3.ch

它们都具有相同的内容(德语)。

当我为 domainname3.ch 激活规范标签时,标签看起来像:

<link rel="canonical" href="http://dimainname3.ch" />

但我希望 domainname2 & domainname3 canonicaltag 指向唯一内容所在的 domainname1 !

谢谢!

4

1 回答 1

2

Magento already have a canonical tool for products and categories ... how does this work with multi stores?

It does not currently have this ability out of the box, so you will need to set this up with an extension. There are many ways you could go about this, but the way I would do it is to modify rel="canonical" links when they get added.

In my new or modified extension I would extend Mage_Page_Block_Html_Head and override the method addLinkRel() to do something like this:

class My_Page_Block_Html_Head extends Mage_Page_Block_Html_Head
{
    /**
     * Add Link element to HEAD entity
     * Overridden to support new canonical cross domain feature.
     *
     * @param string $rel forward link types
     * @param string $href URI for linked resource
     * @return Mage_Page_Block_Html_Head
     */
    public function addLinkRel($rel, $href)
    {
        if ($rel == 'canonical' && $ccd = Mage::getStoreConfig('design/head/canonical_cross_domain')) {
            $href = preg_replace('/(https?:\/\/)[^\/]+(\/.*)/', "$1$ccd$2", $href);
        }
        return parent::addLinkRel($rel, $href);
    }
}

For this to work as intended, I would need to insert value(s) into the core_config_data database table. This can be done manually, or even better, in my extension I could set up a new field in the admin configuration section General / Design / HTML Head. I won’t walk through that here since it is just a nice touch. The values to add would be something like this:

INSERT INTO core_config_data
    (scope, scope_id, path, value)
VALUES
    ('stores', STORE_ID_FOR_DOMAIN2, 'design/head/canonical_cross_domain', 'domainname1.at'),
    ('stores', STORE_ID_FOR_DOMAIN3, 'design/head/canonical_cross_domain', 'domainname1.at');

Now anytime Magento is adding the standard rel="canonical" links where it normally would, it will first check if there is a cross domain configured for the current store view and substitute in that domain name instead of the current one.

于 2015-04-20T22:50:16.340 回答