产品URL在一个共享的购物车在Magento多商店网站


Product URL in a shared shopping cart in Magento multi-store websites

我有Magento多商店网站,我希望用户能够从所有网站将产品添加到他的购物车中并支付一次。

我用这篇文章成功地做到了。

但是当用户点击购物车中的产品时,他没有被重定向到正确的网站。这是文章最后描述的一个限制。

用于编辑购物车中的项目的链接将把客户重定向到原来的购物车网站。你可以改变它,你可以覆盖它getUrl方法用于购物车项块或重写控制器。

我找不到任何解释如何做这个覆盖。

有人能帮我做这个吗?

谢谢

在我的情况下,我看到购物车的项目文件。在php中,它使用了getproducturl()。因此,我在文件/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php第152行修改了该方法。我的条件是,如果它的主要网站不改变,否则它会在url中添加存储代码,如www.example/store1/Producturl。

我希望这对你有帮助。

As You Require The File方法。检查下面的代码。

    public function getProductUrl()
        {
            if (!is_null($this->_productUrl)) {
                return $this->_productUrl;
            }
            if ($this->getItem()->getRedirectUrl()) {
                return $this->getItem()->getRedirectUrl();
            }
            $product = $this->getProduct();
            $option  = $this->getItem()->getOptionByCode('product_type');
            if ($option) {
                $product = $option->getProduct();
            }
            $webids = $product->getWebsiteIds();
            $wid = array();
            foreach($webids as $webid){
                $wid[] = $webid;
            }
            if(!in_array(1,$wid)){
                $website = Mage::app()->getWebsite($wid[0])->getCode();
                $org_url = $product->getUrlModel()->getUrl($product);
                $mod_url = str_replace("www.example.com/index.php/","www.example.com/".$website."/index.php/",$org_url);
                return $mod_url;
            }
            return $product->getUrlModel()->getUrl($product);
        }

作为我的第一个网站id是"1",这就是为什么我使用in_array(1.$wid)。你可以在那里使用你的主网站id。在str_replace中,你可以使用baseurl()方法代替我使用的静态值。