Skip to content

Commit

Permalink
Merge pull request #1170 from mailchimp/Issue-1167-2.3
Browse files Browse the repository at this point in the history
closes #1167 for magento 2.3
  • Loading branch information
gonzaloebiz authored May 12, 2021
2 parents 711dcdd + 8d8d814 commit 72f0eff
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Observer/Adminhtml/Product/ImportAfter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Ebizmarts\MailChimp\Observer\Adminhtml\Product;

use Magento\Framework\Event\Observer;

class ImportAfter implements \Magento\Framework\Event\ObserverInterface
{
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
protected $helper;
protected $productRepository;

/**
* ImportAfter constructor.
* @param \Ebizmarts\MailChimp\Helper\Data $helper
*/
public function __construct(
\Ebizmarts\MailChimp\Helper\Data $helper,
\Magento\Catalog\Model\ProductRepository $productRepository
)
{
$this->helper = $helper;
$this->productRepository = $productRepository;
}
public function execute(Observer $observer)
{
try {
$bunch = $observer->getBunch();
foreach ($bunch as $product) {
$sku = $product['sku'];
$storeId = $product['_store'];
$pro = $this->productRepository->get($sku, false,$storeId);
$id = $pro->getId();
$storeId = $pro->getStoreId();
$this->_updateProduct($pro->getStoreId(), $pro->getId(), null,null,1);
}
} catch (\Exception $e) {
echo $e->getMessage();
}
}
protected function _updateProduct(
$storeId,
$entityId,
$sync_delta = null,
$sync_error = null,
$sync_modified = null
) {
$mailchimpStoreId = $this->helper->getConfigValue(
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,
$storeId
);
$this->helper->saveEcommerceData(
$mailchimpStoreId,
$entityId,
\Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT,
$sync_delta,
$sync_error,
$sync_modified
);
}
}
3 changes: 3 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
<event name="newsletter_subscriber_save_after">
<observer name="mailchimp_newsletter_subscriber_save_after" instance="\Ebizmarts\MailChimp\Observer\Subscriber\SaveAfter" />
</event>
<event name="catalog_product_import_bunch_save_after">
<observer name="mailchimp_product_import" instance="\Ebizmarts\MailChimp\Observer\Adminhtml\Product\ImportAfter"/>
</event>
</config>

0 comments on commit 72f0eff

Please sign in to comment.