Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“制造Magento”;“继续购物”;按钮重定向到上次添加到购物车产品&x27;s类_Magento_Continue - Fatal编程技术网

“制造Magento”;“继续购物”;按钮重定向到上次添加到购物车产品&x27;s类

“制造Magento”;“继续购物”;按钮重定向到上次添加到购物车产品&x27;s类,magento,continue,Magento,Continue,“继续购物”按钮在“购物车”页面上未按我所希望的方式工作 当我点击按钮,然后转到主页 我想转到上一个分类页面。您描述的按钮确实有效。返回主页可能是标准的Magento行为之一 为了回答你的问题,这里是你能做的 请注意,如果产品存在多个类别,这将重定向到它所附加的第一个类别。 这些代码已在Magento 1.7.0.0上成功测试 PHP代码将是: <?php $lastProductAddedToCartId = Mage::getSingleton('checkout/sessio

“继续购物”按钮在“购物车”页面上未按我所希望的方式工作

当我点击按钮,然后转到主页


我想转到上一个分类页面。

您描述的按钮确实有效。返回主页可能是标准的Magento行为之一

为了回答你的问题,这里是你能做的

请注意,如果产品存在多个类别,这将重定向到它所附加的第一个类别。

这些代码已在Magento 1.7.0.0上成功测试

PHP代码将是:

<?php
    $lastProductAddedToCartId = Mage::getSingleton('checkout/session')->getLastAddedProductId();
    if($lastProductAddedToCartId) {
        $productCategoryIdsArray = Mage::getModel('catalog/product')->load($lastProductAddedToCartId)->getCategoryIds();
        $continueShoppingCategoryUrl = Mage::getModel('catalog/category')->load($productCategoryIdsArray[0])->getUrl();
    }
?>

2) 或者(在我看来不太好),重写
Mage\u Checkout\u Block\u Cart::getContinueShoppingUrl()
方法。

如您所述的按钮确实有效。返回主页可能是标准的Magento行为之一

为了回答你的问题,这里是你能做的

请注意,如果产品存在多个类别,这将重定向到它所附加的第一个类别。

这些代码已在Magento 1.7.0.0上成功测试

PHP代码将是:

<?php
    $lastProductAddedToCartId = Mage::getSingleton('checkout/session')->getLastAddedProductId();
    if($lastProductAddedToCartId) {
        $productCategoryIdsArray = Mage::getModel('catalog/product')->load($lastProductAddedToCartId)->getCategoryIds();
        $continueShoppingCategoryUrl = Mage::getModel('catalog/category')->load($productCategoryIdsArray[0])->getUrl();
    }
?>

2) 或者(在我看来不太好),重写
Mage\u Checkout\u Block\u Cart::getContinueShoppingUrl()
方法。

在对我的第一个答案进行评论之后,我制作了一个更复杂的脚本,它与第一个答案相比更需要资源,因此我将其作为单独的答案发布。请注意,PHP端和PHTML端都是不同的

以下是我在Magento CE 1.7.0.0上成功测试的内容。 下面的场景在我提供的注释代码中按预期工作


目录配置 A类(家具)

  • 产品1(沙发)
B类(电子产品)

  • 产品2(台式机)
  • 产品3(笔记本电脑)

脚本 a) 将产品1添加到购物车=>“继续购物”在添加后立即重定向到类别a

b) 导航站点并返回购物车,而不添加新产品=>“继续购物”重定向至类别a

c) 将产品2添加到购物车=>“继续购物”在添加后立即重定向到类别B

d) 导航站点并返回购物车而不添加新产品=>“继续购物”重定向到主页,因为购物车中的产品不属于同一类别

e) 从购物车中删除产品1=>“继续购物”始终重定向到类别B

f) 将产品3添加到购物车=>“继续购物”始终重定向到类别B


PHP代码


HTML按钮代码
在对我的第一个答案发表评论之后,我制作了一个更复杂的脚本,它比第一个答案更需要资源,因此我将其作为单独的答案发布。请注意,PHP端和PHTML端都是不同的

以下是我在Magento CE 1.7.0.0上成功测试的内容。 下面的场景在我提供的注释代码中按预期工作


目录配置 A类(家具)

  • 产品1(沙发)
B类(电子产品)

  • 产品2(台式机)
  • 产品3(笔记本电脑)

脚本 a) 将产品1添加到购物车=>“继续购物”在添加后立即重定向到类别a

b) 导航站点并返回购物车,而不添加新产品=>“继续购物”重定向至类别a

c) 将产品2添加到购物车=>“继续购物”在添加后立即重定向到类别B

d) 导航站点并返回购物车而不添加新产品=>“继续购物”重定向到主页,因为购物车中的产品不属于同一类别

e) 从购物车中删除产品1=>“继续购物”始终重定向到类别B

f) 将产品3添加到购物车=>“继续购物”始终重定向到类别B


PHP代码


HTML按钮代码
感谢您的详细描述。但当我点击“继续购物”按钮时,转到产品详细信息页面。我想进入产品分类页面。请看我的其他答案。仅供记录:只有在添加产品后立即重定向到购物车时,它才会转到类别页面。如果您在其他任何时候去购物车,Magento都无法分辨最后添加的产品是哪一个,如果购物车中有多个产品,则更是如此。如果项目不属于同一类别,Magento如何判断要转到哪个类别?请尝试将产品添加到购物车,并在添加后立即单击“继续购物”。会有用的。谢谢你的详细描述。但当我点击“继续购物”按钮时,转到产品详细信息页面。我想进入产品分类页面。请看我的其他答案。仅供记录:只有在添加产品后立即重定向到购物车时,它才会转到类别页面。如果您在其他任何时候去购物车,Magento都无法分辨最后添加的产品是哪一个,如果购物车中有多个产品,则更是如此。如果项目不属于同一类别,Magento如何判断要转到哪个类别?请尝试将产品添加到购物车,并在添加后立即单击“继续购物”。会有用的。我知道这是一年前的事了,但你会不会碰巧知道如何按商店过滤?如上所述,它属于产品的第一个类别,即使在不同的商店。我尝试过很多过滤方法,但似乎都不管用。我知道这已经有一年了,但你会知道如何通过商店过滤吗?如上所述,它属于产品的第一个类别,即使在不同的商店。我尝试过许多过滤方法,但似乎都不管用。
setLocation('<?php echo (Mage::helper('myhelper')->getContinueShoppingCategoryUrl()) ? Mage::helper('myhelper')->getContinueShoppingCategoryUrl() : $this->getContinueShoppingUrl(); ?>')
<?php
    $continueShoppingCategoryUrl = false;

    /**
     * If we are on the cart page just after we added an item to the cart,
     * we use its category for "Continue Shopping" redirect
     */
    $lastProductAddedToCartId = Mage::getSingleton('checkout/session')->getLastAddedProductId();
    if($lastProductAddedToCartId) {
        $productCategoryIdsArray = Mage::getModel('catalog/product')->load($lastProductAddedToCartId)->getCategoryIds();
        $continueShoppingCategoryUrl = Mage::getModel('catalog/category')->load($productCategoryIdsArray[0])->getUrl();
    }

    /**
     * Otherwise, if we are on the cart page at any other moment, we make sure
     * that all items do belong to the same category and, if this is
     * the case, we use this unique category for "Continue Shopping" redirect
     * 
     * If all cart items do not belong to the same category, we are
     * compelled to let Magento process in its standard way because we 
     * cannot tell which category is the one to redirect to!
     */
    if(!$continueShoppingCategoryUrl) {
        $allCategoryIds = array();
        $cartItems = Mage::helper('checkout/cart')->getQuote()->getAllVisibleItems();
        foreach($cartItems as $cartItem) {
            $productCategoryIds = Mage::getModel('catalog/product')->load($cartItem->getProductId())->getCategoryIds();
            $allCategoryIds = array_merge($allCategoryIds, $productCategoryIds);
        }
        $allCategoryIds = array_unique($allCategoryIds);
        if(count($allCategoryIds) === 1) {
            $continueShoppingCategoryUrl = Mage::getModel('catalog/category')->load(reset($allCategoryIds))->getUrl();
        }
    }
?>
<button type="button" title="Continue Shopping" class="button btn-continue" onclick="setLocation('<?php echo ($continueShoppingCategoryUrl) ? $continueShoppingCategoryUrl : $this->getContinueShoppingUrl(); ?>')"><span><span>Continue Shopping</span></span></button>