-
29-09-2020 - |
题
我在MultiStore上使用此事件观察者进行自定义URL结构制造商在产品网址中关键。
现在问题是我只需要一个特定的商店ID。如何为特定商店ID设置自定义事件观察者?
解决方案
如果您在右侧商店视图上,您只能检查观察者内部。
public function updateurl($observer)
{
$storeId = your store id here;
if (Mage::app()->getStore()->getId() == $storeId) {
//your code goes here.
}
}
. 其他提示
在这种情况下,我建议您使用catalog_product_save_after
。
如果您想要特定商店然后使用为您的产品存储ID提供的$observer->getEvent()->getProduct()->getStoreId()
。
看看为什么我建议您使用$observer->getEvent()->getProduct()->getStoreId()
,因为这个链接如何在产品保存观察者中获取正确的商店上下文?
所以您需要在观察者
上放置以下条件if ($observer->getEvent()->getProduct()->getStoreId() == 'Your_Match_Store_id') {
}
.
观察者
class MageStack_24869_Model_Observer
{
public function updateurl($observer)
{
if ($observer->getEvent()->getProduct()) {
if ($observer->getEvent()->getProduct()->getStoreId() == 'Your_Match_Store_id') {
$product = $observer->getEvent()->getProduct();
$url = '';
if (!is_null($product->getData('country_of_manufacture'))) {
$url .= $product->getAttributeText('country_of_manufacture') . '-';
}
if (!is_null($product->getData('sku'))) {
$url .= $product->getData('sku') . '-';
}
if(!is_null($product->getData('name'))) {
$url .= $product->getData('name');
}
$product->setData('url_key', $url);
}
}
}
}
.