簡體   English   中英

如何過濾magento廢棄的購物車報告集合

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

我正在使用此代碼獲取所有廢棄的購物車。

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

我想要的是讓購物車不早於某個特定日期,我也嘗試了下面的代碼來實現它,但它不起作用。

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

另一件事我如何 addAttributeToselect() 來獲取所需的數據,而不是全部。如果有人還可以提供一些其他過濾器示例的答案,將不勝感激。提前致謝

所以經過大量的搜索,我終於找到了這樣做的方法。 函數 prepareForAbandonedReport() 正在執行所有過濾步驟,因此我打開包含此函數的文件,復制其代碼並在我的代碼中使用它並根據我的需要對其進行更改。 這是我使用的代碼,我希望這會對某人有所幫助。

        $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();

請使用以下代碼,這可能會有所幫助 -

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

由於這個答案對我有很大幫助,我將分享我自己的解決方案(在 Magento EE 1.13.1.0 中測試):

  1. 覆蓋Mage_Reports_Model_Resource_Quote_Collection
  2. 創建_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. 編輯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