- Es gibt kein solches Ereignis, um verlassene Wagen zu erhalten. Sie müssen es benutzerdefiniert erstellen.
- Ich habe die Idee, dies zu überwinden. Sie müssen einen Cron erstellen, der jedes Mal ausgeführt wird, und alle Angebote sammeln, die nicht bestellt sind, und zwischen der von Ihnen festgelegten Zeit (Differenz zwischen der erstellten und der aktualisierten Angebotszeit). Sie müssen nur verwalten
updatedAtFrom
undupdatedAtTo
- Auf diese Weise sammeln Sie alle Angebotsdaten und in dieser Sammlung können Sie das Ereignis versenden und alle Angebotsdaten und Kundendaten innerhalb eines einzelnen Ereignisses an dieses Ereignis übergeben oder für alle Angebote saperieren und diese Daten vom Beobachter an die API übergeben.
Ich habe ein Skript erstellt, das Sie in Ihrer Blockierungsfunktion anwenden können. Ich verwende dieses Arbeitsskript, um Warenkorbartikel per Post an meinen Kunden zu senden, nachdem dieser ohne Bestellung abgereist ist.
<?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
}
?>
Die resultierende Abfrage des obigen Skripts lautet:
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