- 没有这样的事件来得到废弃的购物车,您必须自定义它。
- 我有克服的想法,您必须创建在每个特定时间运行的cron并收集所有未排序的报价以及您设置的时间之间(创建的报价时间与更新的报价时间之间的差)。你只需要管理
updatedAtFrom
和updatedAtTo
- 这样,您将收集所有报价数据,并且在该集合中,您可以调度事件并将所有报价数据和客户数据传递给单个事件内的事件,也可以对所有报价进行合理化处理,然后将数据从观察者传递给API。
我创建了可以在您的阻止功能中应用的脚本,我正在使用此工作脚本将购物车中的商品通过邮件发送给我的客户,因为他们没有订单就离开了。
<?php
ob_start();
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
ini_set('memory_limit', '1024M');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->create('Magento\Framework\App\ResourceConnection');
$updatedAtFrom = '2019-06-19 19:00:00'; //Add current time
$updatedAtTo = '2019-06-19 20:30:00'; // $updatedAtFrom + 90 minutes ,add 90 minutes in current time to abondened cart
$connection = $resource->getConnection();
$select = $connection->select()
->from(
['q' => $resource->getTableName('quote')],
[
'store_id' => 'q.store_id',
'quote_id' => 'q.entity_id',
'customer_id' => 'q.customer_id',
'updated_at' => 'q.updated_at',
'created_at' => 'q.created_at',
]
)
->joinLeft(
['qa' => $resource->getTableName('quote_address')],
'q.entity_id = qa.quote_id AND qa.address_type = "billing"',
[
'customer_email' => new \Zend_Db_Expr('IFNULL(q.customer_email, qa.email)'),
'customer_firstname' => new \Zend_Db_Expr('IFNULL(q.customer_firstname, qa.firstname)'),
'customer_lastname' => new \Zend_Db_Expr('IFNULL(q.customer_lastname, qa.lastname)'),
]
)
->joinInner(
['qi' => $resource->getTableName('quote_item')],
'q.entity_id = qi.quote_id',
[
'i_created_at' => new \Zend_Db_Expr('MAX(qi.created_at)'),
]
)
->joinLeft(array('order' => $resource->getTableName('sales_order')),
'order.quote_id = q.entity_id',
array()
)
->where('order.entity_id IS NULL')
->where('q.is_active = 1')
->where('q.items_count > 0')
->where('q.customer_email IS NOT NULL OR qa.email IS NOT NULL')
->where('qi.parent_item_id IS NULL')
->group('q.entity_id')
->having(
'(q.created_at > ? OR MAX(qi.created_at) > ?)',
$updatedAtFrom
)
->having(
'(q.created_at < ? OR MAX(qi.created_at) < ?)',
$updatedAtTo
)
->order('q.updated_at');
$quotes = $connection->fetchAll($select);
foreach ($quotes as $quote) {
$params = [
'store_id' => $quote['store_id'],
'quote_id' => $quote['quote_id'],
'customer_id' => $quote['customer_id'],
'customer_email' => $quote['customer_email'],
'customer_tname' => $quote['customer_firstname'] . ' ' . $quote['customer_lastname'],
'created_at' => max($quote['created_at'], $quote['i_created_at']),
];
echo $quote['quote_id'];
/*$this->eventdispatch->register(
'quote_abandoned',
[$params['quote_id']],
$params
);*/
// Dispatch Event here and writelogic in that event which you want
}
?>
以上脚本的结果查询为:
SELECT `q`.`store_id`, `q`.`entity_id` AS `quote_id`, `q`.`customer_id`, `q`.`updated_at`, `q`.`created_at`, IFNULL(q.customer_email, qa.email) AS `customer_email`, IFNULL(q.customer_firstname, qa.firstname) AS `customer_firstname`, IFNULL(q.customer_lastname, qa.lastname) AS `customer_lastname`, MAX(qi.created_at) AS `i_created_at` FROM `quote` AS `q` LEFT JOIN `quote_address` AS `qa` ON q.entity_id = qa.quote_id AND qa.address_type = "billing" INNER JOIN `quote_item` AS `qi` ON q.entity_id = qi.quote_id LEFT JOIN `sales_order` AS `order` ON order.quote_id = q.entity_id WHERE (order.entity_id IS NULL) AND (q.is_active = 1) AND (q.items_count > 0) AND (q.customer_email IS NOT NULL OR qa.email IS NOT NULL) AND (qi.parent_item_id IS NULL) GROUP BY `q`.`entity_id` HAVING ((q.created_at > '2019-06-19 19:00:00' OR MAX(qi.created_at) > '2019-06-19 19:00:00')) AND ((q.created_at < '2019-06-19 20:30:00' OR MAX(qi.created_at) < '2019-06-19 20:30:00')) ORDER BY `q`.`updated_at` ASC