【问题标题】:"My order" table just with orders from current store view“我的订单”表仅包含来自当前商店视图的订单
【发布时间】:2013-03-05 09:02:59
【问题描述】:

我有一个带有多个网站和多个商店/商店视图的 maganto 安装 (1.4.0.1)。此外,我在所有商店视图中都有不同的产品。当我进入我的帐户-> 我的订单在表格中显示来自所有商店的订单。我可以在某处进行配置或更改代码中的某些内容,以便仅从当前打开的商店视图中获得带有订单的列表吗?

换句话说,如果我在我的网站 mywebsite.com/store2 的订单 mywebsite.com/store2/sales/order/history/ 上去商店 2,它会显示来自所有网站的订单历史记录,但我需要我显示订单只是表单“store2”。

我希望有人能回答这个或类似的问题,如果能帮助我,我将不胜感激。

约旦

【问题讨论】:

    标签: magento


    【解决方案1】:

    很简单。

    将相应的销售订单历史记录块 app\code\core\Mage\Sales\Block\Order\History.php 文件覆盖到您的本地代码池中

    只需按当前商店 ID 过滤您的收藏。

                 $store_id = Mage::app()->getStore()->getId();
                 $orders = Mage::getResourceModel('sales/order_collection')
            ->addFieldToSelect('*')
            ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
            ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
            ->addFieldToFilter('store_id',$store_id)
            ->setOrder('created_at', 'desc')
        ;
    

    注意上面代码中的这些行

            /*Current Store View ID*/
            $store_id = Mage::app()->getStore()->getId();
    
            /*Filtering the order collection by current store id*/
            ->addFieldToFilter('store_id',$store_id)
    

    【讨论】:

    • 非常感谢,它工作得很好,但现在我需要通过网站而不是网上商店来列出订单,我尝试使用 $website_id= Mage::app()->getStore() ->getWebsiteId();和 addFieldToFilter('website_id',$website_id) 但不起作用,一些建议
    • @JovanovJordan 显然订单集合不能按 website_id 排序,因为它没有。此外,我们已经通过 store_id 过滤了集合,集合仅包含该商店视图的订单。
    • 再次嗨,但我想删除选择表单 store_id 并通过网站选择。另一种方式的一些建议
    • @JovanovJordan 刚刚为您的最新查询添加了另一个答案
    【解决方案2】:
        /*GetCurrent Website Name*/
        $currentWebsiteName = Mage::app()->getStore()->getWebsite()->getName();        
        $currentWebsiteName_LIKE_PHRASE = '%'.$currentWebsiteName.'%';
    
        /*Filter the Order Collection by Current Website Name*/
        $orders = Mage::getResourceModel('sales/order_collection')
            ->addFieldToSelect('*')
            ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
            ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
            ->addAttributeToFilter('store_name', array('like' => $currentWebsiteName_LIKE_PHRASE))
            ->setOrder('created_at', 'desc');
    
       /*Note the Below Line*/
       ->addAttributeToFilter('store_name', array('like' => $currentWebsiteName_LIKE_PHRASE))
    

    我按当前网站名称过滤。刚拿到 sales_flat_order 表可以查看“store_name”这一列,您可以在其中找到它还包含网站名称

    很遗憾,我无法在此主订单表或其相关表中找到 网站 ID 以对订单集合进行JOIN 语句。我认为您可能有一些带有 **_website 后缀**的订单表,如果是这样,您可以轻松地将其加入到我们现有的集合中

    【讨论】:

    • 谢谢,它需要我。 :)
    猜你喜欢
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 2021-12-23
    • 2014-02-18
    • 2021-03-23
    • 2011-12-12
    • 1970-01-01
    • 2021-09-04
    相关资源
    最近更新 更多