Skip to content

Commit

Permalink
fix the sync helper #1714 for magento 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Jun 29, 2023
1 parent cfc022f commit e3a1089
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions Helper/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\ValidatorException;
use Magento\Sales\Model\OrderFactory;
use Magento\Catalog\Model\ProductFactory;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory as OrderCollectionFactory;
use Ebizmarts\MailChimp\Model\MailChimpSyncEcommerceFactory;
use Ebizmarts\MailChimp\Model\MailChimpSyncEcommerce;
Expand Down Expand Up @@ -33,6 +34,10 @@ class Sync extends AbstractHelper
* @var OrderCollectionFactory
*/
private $orderCollectionFactory;
/**
* @var ProductFactory
*/
private $productFactory;

/**
* @param Context $context
Expand All @@ -41,20 +46,23 @@ class Sync extends AbstractHelper
* @param MailChimpSyncEcommerce $chimpSyncEcommerce
* @param OrderFactory $orderFactory
* @param OrderCollectionFactory $orderCollectionFactory
* @param ProductFactory $productFactory
*/
public function __construct(
Context $context,
MailChimpSyncEcommerceFactory $chimpSyncEcommerceFactory,
MailChimpErrors $mailChimpErrors,
MailChimpSyncEcommerce $chimpSyncEcommerce,
OrderFactory $orderFactory,
OrderCollectionFactory $orderCollectionFactory
OrderCollectionFactory $orderCollectionFactory,
ProductFactory $productFactory
) {
$this->chimpSyncEcommerceFactory = $chimpSyncEcommerceFactory;
$this->mailChimpErrors = $mailChimpErrors;
$this->chimpSyncEcommerce = $chimpSyncEcommerce;
$this->orderFactory = $orderFactory;
$this->orderCollectionFactory = $orderCollectionFactory;
$this->productFactory = $productFactory;
parent::__construct($context);
}
public function saveEcommerceData(
Expand Down Expand Up @@ -82,8 +90,6 @@ public function saveEcommerceData(
}
if ($date) {
$chimpSyncEcommerce->setMailchimpSyncDelta($date);
} elseif ($modified != 1) {
$chimpSyncEcommerce->setBatchId(null);
}
if ($error) {
$chimpSyncEcommerce->setMailchimpSyncError($error);
Expand All @@ -100,19 +106,33 @@ public function saveEcommerceData(
}
$chimpSyncEcommerce->getResource()->save($chimpSyncEcommerce);
}
if ($type==\Ebizmarts\MailChimp\Helper\Data::IS_ORDER) {
if ($sent||$error) {
$order = $this->orderFactory->create()->loadByAttribute('entity_id', $entityId);
if ($sent) {
$order->setMailchimpSent($sent);
switch ($type) {
case \Ebizmarts\MailChimp\Helper\Data::IS_ORDER :
if ($sent || $error) {
$order = $this->orderFactory->create()->loadByAttribute('entity_id', $entityId);
if ($sent) {
$order->setMailchimpSent($sent);
}
if ($error) {
$order->setMailchimpSyncError($error);
}
$order->save();
}
if ($error) {
$order->setMailchimpSyncError($error);
break;
case \Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT :
if ($sent || $error) {
$product = $this->productFactory->create()->load($entityId);
$product->setSync(true);
if ($sent) {
$product->setMailchimpSent($sent);
}
if ($error) {
$product->setMailchimpSyncError($error);
}
$product->save();
}
$order->save();
}
}
}
break;
} }
}
public function getChimpSyncEcommerce($storeId, $id, $type)
{
Expand Down

0 comments on commit e3a1089

Please sign in to comment.