简体   繁体   English

如何过滤magento废弃的购物车报告集合

[英]How to Filter the magento abandoned cart report collection

I am using this code to get all the abandoned carts.我正在使用此代码获取所有废弃的购物车。

$storeIds = array(1);
    $collection = Mage::getResourceModel('reports/quote_collection');
    $collection->prepareForAbandonedReport($storeIds);
    $collection->load();

What I want is that to get the carts not older than some specific date, I have also tried code below to achieve it, but its not working.我想要的是让购物车不早于某个特定日期,我也尝试了下面的代码来实现它,但它不起作用。

$collection->addFieldToFilter(array("main_table.created_at"=>Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('-1 week'))));

Another thing how can I addAttributeToselect() to get the required data, not all.If someone can also provide the answers with some other filter examples it will be very grateful.Thanks in advance另一件事我如何 addAttributeToselect() 来获取所需的数据,而不是全部。如果有人还可以提供一些其他过滤器示例的答案,将不胜感激。提前致谢

So after alot of searching I finally found the way to do it.所以经过大量的搜索,我终于找到了这样做的方法。 The function prepareForAbandonedReport() is doing all the filteration steps, so I open the file containing this function, copied its code and used it in my code and altered it according to my needs.函数 prepareForAbandonedReport() 正在执行所有过滤步骤,因此我打开包含此函数的文件,复制其代码并在我的代码中使用它并根据我的需要对其进行更改。 Here is the code I used,I hope this will help someone.这是我使用的代码,我希望这会对某人有所帮助。

        $collection = Mage::getResourceModel('reports/quote_collection')
        ->addFieldToFilter('items_count', array('neq' => '0'))
        ->addFieldToFilter('main_table.is_active', '1')
        ->addFieldToFilter('main_table.created_at', array('gt' => date("Y-m-d H:i:s", strtotime('-2 month'))))
        ->addSubtotal($storeIds, null)
        ->addCustomerData(null)
        ->setOrder('updated_at')
        ->addFieldToFilter('store_id', array('in' => $storeIds));
    $collection->load();

Please use following code this may help -请使用以下代码,这可能会有所帮助 -

$collection = Mage::getResourceModel('reports/quote_collection');
$collection->prepareForAbandonedReport();
$output = $collection->load()->toArray();

Since this answer help me a lot, i'll share my own solution (tested in Magento EE 1.13.1.0):由于这个答案对我有很大帮助,我将分享我自己的解决方案(在 Magento EE 1.13.1.0 中测试):

  1. Override Mage_Reports_Model_Resource_Quote_Collection覆盖Mage_Reports_Model_Resource_Quote_Collection
  2. Create _filterDate() method:创建_filterDate()方法:

     public function _filterDate($key, $filter) { if (array_key_exists($key, $filter)) { $filterDate = $filter[$key]; if (array_key_exists('from', $filterDate)) { $fromRawDate = $filter[$key]['from']; $dateFrom = str_replace('/', '-', $fromRawDate); $dateStart = date('Ym-d', strtotime($dateFrom)) . ' 00:00:00'; } if (array_key_exists('to', $filterDate)) { $toRawDate = $filter[$key]['to']; $dateTo = str_replace('/', '-', $toRawDate); $dateEnd = date('Ym-d', strtotime($dateTo)) . ' 23:59:59'; } if ( ! empty($dateStart) && ! empty($dateEnd) ) { $this->addFieldToFilter('`main_table`.`' . $key . '`', array('from' => $dateStart, 'to' => $dateEnd)); } else if ( ! empty($dateStart) && empty($dateEnd) ) { $this->addFieldToFilter('`main_table`.`' . $key . '`', array('from' => $dateStart)); } else if ( ! empty($dateEnd) && empty($dateStart) ) { $this->addFieldToFilter('`main_table`.`' . $key . '`', array('to' => $dateEnd)); } } }
  3. Edit prepareForAbandonedReport() and use _filterDate() :编辑prepareForAbandonedReport()并使用_filterDate()

     public function prepareForAbandonedReport($storeIds, $filter = null) { self::_filterDate('created_at', $filter); // Used to filter created_at field self::_filterDate('updated_at', $filter); // Used to filter updated_at field $this->addFieldToFilter('items_count', array('neq' => '0')) ->addFieldToFilter('main_table.is_active', '1') ->addSubtotal($storeIds, $filter) ->addCustomerData($filter) ->setOrder('updated_at'); if (is_array($storeIds) && !empty($storeIds)) { $this->addFieldToFilter('store_id', array('in' => $storeIds)); } return $this; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM