-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1170 from mailchimp/Issue-1167-2.3
closes #1167 for magento 2.3
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters