From c568b0af8e6aa3ea6fef6b9c109ed0c04e8ddb0d Mon Sep 17 00:00:00 2001 From: prime Date: Tue, 26 Jan 2021 14:57:05 +0700 Subject: [PATCH 01/17] Other Update - add store data when test connection, add tag to order --- Helper/EmailMarketing.php | 195 +++++++++++++++++++++++++------------- 1 file changed, 129 insertions(+), 66 deletions(-) mode change 100644 => 100755 Helper/EmailMarketing.php diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php old mode 100644 new mode 100755 index 9d310ab..65a8a4c --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -59,9 +59,12 @@ use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\ResourceModel\Order\Collection as OrderCollection; use Magento\Shipping\Helper\Data as ShippingHelper; +use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use Psr\Log\LoggerInterface; use Magento\Sales\Model\Order\Config as OrderConfig; +use Magento\Store\Model\Information; +use Magento\Store\Model\StoreFactory; /** * Class EmailMarketing @@ -71,16 +74,16 @@ class EmailMarketing extends Data { const IS_SYNCED_ATTRIBUTE = 'mp_smtp_is_synced'; - const APP_URL = 'https://app.avada.io/app/api/v1/checkouts'; - const CUSTOMER_URL = 'https://app.avada.io/app/api/v1/customers'; - const ORDER_URL = 'https://app.avada.io/app/api/v1/orders'; - const ORDER_COMPLETE_URL = 'https://app.avada.io/app/api/v1/orders/complete'; - const INVOICE_URL = 'https://app.avada.io/app/api/v1/orders/invoice'; - const SHIPMENT_URL = 'https://app.avada.io/app/api/v1/orders/ship'; - const CREDITMEMO_URL = 'https://app.avada.io/app/api/v1/orders/refund'; - const DELETE_URL = 'https://app.avada.io/app/api/v1/checkouts?id='; - const SYNC_CUSTOMER_URL = 'https://app.avada.io/app/api/v1/customers/bulk'; - const SYNC_ORDER_URL = 'https://app.avada.io/app/api/v1/orders/bulk'; + const APP_URL = 'https://app.avada.io/app/api/v1/checkouts'; + const CUSTOMER_URL = 'https://app.avada.io/app/api/v1/customers'; + const ORDER_URL = 'https://app.avada.io/app/api/v1/orders'; + const ORDER_COMPLETE_URL = 'https://app.avada.io/app/api/v1/orders/complete'; + const INVOICE_URL = 'https://app.avada.io/app/api/v1/orders/invoice'; + const SHIPMENT_URL = 'https://app.avada.io/app/api/v1/orders/ship'; + const CREDITMEMO_URL = 'https://app.avada.io/app/api/v1/orders/refund'; + const DELETE_URL = 'https://app.avada.io/app/api/v1/checkouts?id='; + const SYNC_CUSTOMER_URL = 'https://app.avada.io/app/api/v1/customers/bulk'; + const SYNC_ORDER_URL = 'https://app.avada.io/app/api/v1/orders/bulk'; /** * @var UrlInterface @@ -211,7 +214,17 @@ class EmailMarketing extends Data /** * @var null */ - protected $_salesAmountExpression= null; + protected $_salesAmountExpression = null; + + /** + * @var Information + */ + protected $storeInfo; + + /** + * @var StoreFactory + */ + protected $storeFactory; /** * EmailMarketing constructor. @@ -239,6 +252,8 @@ class EmailMarketing extends Data * @param TimezoneInterface $localeDate * @param Config $addressConfig * @param LoggerInterface $logger + * @param Information $storeInfo + * @param StoreFactory $storeFactory */ public function __construct( Context $context, @@ -263,7 +278,9 @@ public function __construct( OrderConfig $orderConfig, TimezoneInterface $localeDate, Config $addressConfig, - LoggerInterface $logger + LoggerInterface $logger, + Information $storeInfo, + StoreFactory $storeFactory ) { parent::__construct($context, $objectManager, $storeManager); @@ -287,6 +304,8 @@ public function __construct( $this->orderConfig = $orderConfig; $this->_localeDate = $localeDate; $this->_addressConfig = $addressConfig; + $this->storeInfo = $storeInfo; + $this->storeFactory = $storeFactory; } /** @@ -341,7 +360,7 @@ public function splitSku($sku) public function getFormatedOptionValue(array $optionValue) { $params = [ - 'max_length' => 55, + 'max_length' => 55, 'cut_replacer' => ' ...' ]; @@ -356,12 +375,12 @@ public function getFormatedOptionValue(array $optionValue) */ public function getRecoveryUrl(Quote $quote) { - $store = $this->storeManager->getStore($quote->getStoreId()); + $store = $this->storeManager->getStore($quote->getStoreId()); $routeParams = [ '_current' => false, - '_nosid' => true, - 'token' => $quote->getMpSmtpAceToken() . '_' . base64_encode($quote->getId()), - '_secure' => $store->isUrlSecure() + '_nosid' => true, + 'token' => $quote->getMpSmtpAceToken() . '_' . base64_encode($quote->getId()), + '_secure' => $store->isUrlSecure() ]; $this->frontendUrl->setScope($quote->getStoreId()); @@ -420,7 +439,7 @@ public function getSecretKey($storeId = null) public function getQuoteUpdatedAt($quoteId) { $connection = $this->getResourceQuote()->getConnection(); - $select = $connection->select()->from($this->getResourceQuote() + $select = $connection->select()->from($this->getResourceQuote() ->getMainTable(), 'updated_at') ->where('entity_id = :id'); @@ -483,13 +502,14 @@ public function getOrderData($object) } } - $data['email'] = $customerEmail; + $data['email'] = $customerEmail; $data['customer'] = [ 'id' => $customerId, 'email' => $customerEmail, 'first_name' => $customerFirstname ?: '', 'last_name' => $customerLastname ?: '', - 'telephone' => $object->getBillingAddress()->getTelephone() ?: '' + 'telephone' => $object->getBillingAddress()->getTelephone() ?: '', + 'tags' => $this->getTags($this->customerFactory->create()->load($customerId)) ]; if (!$isInvoice) { $data['order_status_url'] = $this->getOrderViewUrl($object->getStoreId(), $object->getId(), $path); @@ -498,12 +518,12 @@ public function getOrderData($object) if ($isShipment) { if ($object->getData('tracks')) { $data['trackingUrl'] = $this->shippingHelper->getTrackingPopupUrlBySalesModel($object); - $tracks = []; + $tracks = []; foreach ($object->getData('tracks') as $track) { $tracks[] = [ 'company' => $track->getTitle(), - 'number' => $track->getTrackNumber(), - 'url' => $this->shippingHelper->getTrackingPopupUrlBySalesModel($track) + 'number' => $track->getTrackNumber(), + 'url' => $this->shippingHelper->getTrackingPopupUrlBySalesModel($track) ]; } @@ -534,13 +554,14 @@ public function getOrderData($object) } if ($object instanceof Order) { - $data['status'] = $object->getStatus(); - $data['state'] = $object->getState(); - $data['total_price'] = $object->getBaseGrandTotal(); - $data['subtotal_price'] = $object->getBaseSubtotal(); - $data['total_tax'] = $object->getBaseTaxAmount(); - $data['total_weight'] = $object->getTotalWeight() ?: '0'; - $data['total_discounts'] = $object->getBaseDiscountAmount(); + $data['status'] = $object->getStatus(); + $data['state'] = $object->getState(); + $data['total_price'] = $object->getBaseGrandTotal(); + $data['subtotal_price'] = $object->getBaseSubtotal(); + $data['total_tax'] = $object->getBaseTaxAmount(); + $data['total_weight'] = $object->getTotalWeight() ?: '0'; + $data['total_shipping_cost'] = $object->getBaseShippingAmount(); + $data['total_discounts'] = $object->getBaseDiscountAmount(); } return $data; @@ -601,9 +622,9 @@ public function getOrderViewUrl($storeId, $orderId, $path = 'sales/order/view') */ public function getACEData($quote) { - $isActive = (bool)$quote->getIsActive(); + $isActive = (bool)$quote->getIsActive(); $quoteCompletedAt = null; - $updatedAt = $this->getQuoteUpdatedAt($quote->getId()); + $updatedAt = $this->getQuoteUpdatedAt($quote->getId()); //first time created is the same updated $createdAt = $quote->getCreatedAt() ?: $updatedAt; @@ -614,11 +635,11 @@ public function getACEData($quote) } return [ - 'id' => (int) $quote->getId(), + 'id' => (int)$quote->getId(), 'email' => $quote->getCustomerEmail(), 'completed_at' => $quoteCompletedAt, 'customer' => [ - 'id' => (int) $quote->getCustomerId(), + 'id' => (int)$quote->getCustomerId(), 'email' => $quote->getCustomerEmail(), 'name' => $this->getCustomerName($quote), 'first_name' => $quote->getCustomerFirstname(), @@ -653,7 +674,7 @@ public function getShippingAddress(Quote $quote) * @var Address $shippingAddress */ $shippingAddress = $quote->getShippingAddress(); - $address = [ + $address = [ 'name' => $shippingAddress->getName(), 'last_name' => $shippingAddress->getLastname(), 'phone' => $shippingAddress->getTelephone(), @@ -682,7 +703,7 @@ public function getShipmentOrCreditmemoItems($object) $items = []; foreach ($object->getItems() as $item) { $orderItem = $item->getOrderItem(); - $product = $orderItem->getProduct(); + $product = $orderItem->getProduct(); if ($orderItem->getParentItemId() && isset($items[$orderItem->getParentItemId()]['bundle_items'])) { $items[$orderItem->getParentItemId()]['bundle_items'][] = [ 'title' => $item->getName(), @@ -691,7 +712,7 @@ public function getShipmentOrCreditmemoItems($object) 'product_id' => $orderItem->getProductId(), 'sku' => $orderItem->getSku(), 'quantity' => $item->getQty(), - 'price' => (float) $item->getBasePrice() + 'price' => (float)$item->getBasePrice() ]; continue; @@ -701,18 +722,18 @@ public function getShipmentOrCreditmemoItems($object) $items[$orderItem->getParentItemId()]['variant_title'] = $item->getName(); $items[$orderItem->getParentItemId()]['variant_image'] = $this->getProductImage($product); $items[$orderItem->getParentItemId()]['variant_id'] = $orderItem->getProductId(); - $items[$orderItem->getParentItemId()]['variant_price'] = (float) $item->getBasePrice(); + $items[$orderItem->getParentItemId()]['variant_price'] = (float)$item->getBasePrice(); continue; } - $productType = $orderItem->getData('product_type'); + $productType = $orderItem->getData('product_type'); $items[$orderItem->getId()] = [ 'type' => $productType, 'name' => $productType === 'configurable' ? $this->getItemOptions($orderItem) : $item->getName(), 'title' => $item->getName(), - 'price' => (float) $item->getBasePrice(), + 'price' => (float)$item->getBasePrice(), 'quantity' => $item->getQty(), 'sku' => $item->getSku(), 'product_id' => $item->getProductId(), @@ -796,7 +817,7 @@ public function getItemOptions($orderItem) */ public function getCartItems($object) { - $items = []; + $items = []; $isQuote = $object instanceof Quote; foreach ($object->getAllItems() as $item) { @@ -807,13 +828,13 @@ public function getCartItems($object) /** * @var Product $product */ - $product = $item->getProduct(); + $product = $item->getProduct(); $productType = $item->getData('product_type'); $bundleItems = []; - $hasVariant = $productType === 'configurable'; - $isBundle = $productType === 'bundle'; - $name = $item->getName(); + $hasVariant = $productType === 'configurable'; + $isBundle = $productType === 'bundle'; + $name = $item->getName(); if ($hasVariant) { if ($isQuote) { $name = $this->getOptionsWithName($item); @@ -826,8 +847,8 @@ public function getCartItems($object) 'type' => $productType, 'title' => $item->getName(), 'name' => $name, - 'price' => (float) $item->getBasePrice(), - 'quantity' => (int) ($isQuote ? $item->getQty() : $item->getQtyOrdered()), + 'price' => (float)$item->getBasePrice(), + 'quantity' => (int)($isQuote ? $item->getQty() : $item->getQtyOrdered()), 'sku' => $item->getSku(), 'product_id' => $item->getProductId(), 'image' => $this->getProductImage($product), @@ -845,7 +866,7 @@ public function getCartItems($object) if ($hasVariant) { $itemRequest['variant_title'] = $child->getName(); $itemRequest['variant_image'] = $this->getProductImage($product); - $itemRequest['variant_id'] = $child->getProductId(); + $itemRequest['variant_id'] = $child->getProductId(); $itemRequest['variant_price'] = (float)$child->getBasePrice(); } @@ -856,15 +877,15 @@ public function getCartItems($object) 'image' => $this->getProductImage($product), 'product_id' => $child->getProductId(), 'sku' => $child->getSku(), - 'quantity' => (int) ($isQuote ? $child->getQty() : $child->getQtyOrdered()), - 'price' => (float) $child->getBasePrice() + 'quantity' => (int)($isQuote ? $child->getQty() : $child->getQtyOrdered()), + 'price' => (float)$child->getBasePrice() ]; } } } $itemRequest['bundle_items'] = $bundleItems; - $items[] = $itemRequest; + $items[] = $itemRequest; } return $items; @@ -872,6 +893,7 @@ public function getCartItems($object) /** * @param Product $product + * * @return mixed * @throws NoSuchEntityException */ @@ -886,7 +908,7 @@ public function getProductImage($product) $image = '/' . $image; } - $baseUrl = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA); + $baseUrl = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA); $imageUrl = $baseUrl . 'catalog/product' . $image; return str_replace('\\', '/', $imageUrl); @@ -898,6 +920,7 @@ public function getProductImage($product) * @param string $url * @param string $secretKey * @param bool $isTest + * * @return mixed * @throws LocalizedException */ @@ -936,11 +959,11 @@ public function setHeaders($data, $url = '', $appID = '', $secretKey = '', $isTe $this->url = $url; - $body = self::jsonEncode(['data' => $data]); - $storeId = $this->storeId ?: $this->getStoreId(); - $secretKey = $secretKey ?: $this->getSecretKey($storeId); + $body = self::jsonEncode(['data' => $data]); + $storeId = $this->storeId ?: $this->getStoreId(); + $secretKey = $secretKey ?: $this->getSecretKey($storeId); $generatedHash = base64_encode(hash_hmac('sha256', $body, $secretKey, true)); - $appID = $appID ?: $this->getAppID($storeId); + $appID = $appID ?: $this->getAppID($storeId); $this->_curl->addHeader('Content-Type', 'application/json'); $this->_curl->addHeader('X-EmailMarketing-Hmac-Sha256', $generatedHash); $this->_curl->addHeader('X-EmailMarketing-App-Id', $appID); @@ -987,10 +1010,10 @@ public function sendRequestWithoutWaitResponse($data, $url = '', $appID = '', $s public function deleteQuote($id, $storeId) { $this->initCurl(); - $url = self::DELETE_URL . $id; - $secretKey = $this->getSecretKey($storeId); + $url = self::DELETE_URL . $id; + $secretKey = $this->getSecretKey($storeId); $generatedHash = base64_encode(hash_hmac('sha256', '', $secretKey, true)); - $appID = $this->getAppID($storeId); + $appID = $this->getAppID($storeId); $this->_curl->addHeader('Content-Type', 'application/json'); $this->_curl->addHeader('X-EmailMarketing-Hmac-Sha256', $generatedHash); $this->_curl->addHeader('X-EmailMarketing-App-Id', $appID); @@ -1043,11 +1066,11 @@ public function getCustomerData(Customer $customer, $isLoadSubscriber = false, $ { if ($isLoadSubscriber) { - $subscriber = $this->_subscriberFactory->create()->loadByEmail($customer->getEmail()); + $subscriber = $this->_subscriberFactory->create()->loadByEmail($customer->getEmail()); $isSubscriber = $this->isSubscriber($subscriber->getSubscriberStatus()); } else { $subscriberStatus = $customer->getData('subscriber_status'); - $isSubscriber = $this->isSubscriber($subscriberStatus) ?: !!$customer->getIsSubscribed(); + $isSubscriber = $this->isSubscriber($subscriberStatus) ?: !!$customer->getIsSubscribed(); } $data = [ @@ -1072,14 +1095,16 @@ public function getCustomerData(Customer $customer, $isLoadSubscriber = false, $ if ($isUpdateOrder) { $orderCollectionByCustomer = $this->orderCollection->addFieldToFilter('customer_id', $customer->getId()); - $size = $orderCollectionByCustomer->getSize(); - $lastOrderId = $orderCollectionByCustomer->addOrder('entity_id')->getFirstItem()->getId(); + $size = $orderCollectionByCustomer->getSize(); + $lastOrderId = $orderCollectionByCustomer->addOrder('entity_id')->getFirstItem()->getId(); $data['orders_count'] = $size; $data['last_order_id'] = $lastOrderId; $data['total_spent'] = $this->getLifetimeSales($customer->getId()); $data['currency'] = $this->getBaseCurrencyByWebsiteId($customer->getWebsiteId())->getCurrencyCode(); } + \Zend_Debug::dump($data); + die(); return $data; } @@ -1124,7 +1149,7 @@ protected function _getSalesAmountExpression($connection) $expressionTransferObject = new DataObject( [ 'expression' => '%s - %s - %s - (%s - %s - %s)', - 'arguments' => [ + 'arguments' => [ $connection->getIfNullSql('main_table.base_total_invoiced', 0), $connection->getIfNullSql('main_table.base_tax_invoiced', 0), $connection->getIfNullSql('main_table.base_shipping_invoiced', 0), @@ -1161,7 +1186,7 @@ public function updateCustomer($customerId) { if ($customerId) { try { - $customer = $this->getCustomerById($customerId); + $customer = $this->getCustomerById($customerId); $customerData = $this->getCustomerData($customer, true, true); $this->syncCustomer($customerData, false); } catch (Exception $e) { @@ -1184,6 +1209,7 @@ public function getBaseCurrencyByWebsiteId($websiteId) /** * @param string $appID * @param string $secretKey + * * @return mixed * @throws LocalizedException */ @@ -1193,7 +1219,42 @@ public function testConnection($appID, $secretKey) $secretKey = $this->getSecretKey(); } - return $this->sendRequest([['test' => 1]], '', $appID, $secretKey, true); + return $this->sendRequest([['data' => $this->getStoreInformation()]], '', $appID, $secretKey, true); + } + + /** + * @return DataObject + * @throws LocalizedException + * @throws NoSuchEntityException + */ + public function getStoreInformation() + { + $storeObj = $this->storeFactory->create()->load($this->storeManager->getStore()->getId()); + $store = $this->storeInfo->getStoreInformationObject($storeObj); + + return new DataObject([ + 'name' => $store->getName(), + 'phone' => $store->getPhone(), + 'countryName' => $store->getCountry(), + 'countryCode' => $store->getCountryId(), + 'city' => $store->getCity(), + 'timezone' => $this->getConfigData('general/locale/timezone'), + 'zip' => $store->getPostcode(), + 'currency' => $this->getConfigData('currency/options/default'), + 'address1' => $store->getData('street_line1'), + 'address2' => $store->getData('street_line2'), + 'email' => $this->getConfigData('trans_email/ident_sales/email'), + ]); + } + + /** + * @param string $path + * + * @return mixed + */ + public function getConfigData(string $path) + { + return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORES); } /** @@ -1215,6 +1276,7 @@ public function syncCustomer($data, $isCreate = true) /** * @param array $data + * * @return mixed * @throws LocalizedException */ @@ -1225,6 +1287,7 @@ public function syncCustomers($data) /** * @param array $data + * * @return mixed * @throws LocalizedException */ From 30a7dba00500880da53e0338944d4698defbd236 Mon Sep 17 00:00:00 2001 From: prime Date: Tue, 26 Jan 2021 17:28:22 +0700 Subject: [PATCH 02/17] Other Update - fix getTelephone() on null error --- Helper/EmailMarketing.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index 65a8a4c..e284c4b 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -469,6 +469,7 @@ public function formatDate($date) * * @return array * @throws NoSuchEntityException + * @throws LocalizedException */ public function getOrderData($object) { @@ -508,7 +509,7 @@ public function getOrderData($object) 'email' => $customerEmail, 'first_name' => $customerFirstname ?: '', 'last_name' => $customerLastname ?: '', - 'telephone' => $object->getBillingAddress()->getTelephone() ?: '', + 'telephone' => $object->getBillingAddress() ? $object->getBillingAddress()->getTelephone() : '', 'tags' => $this->getTags($this->customerFactory->create()->load($customerId)) ]; if (!$isInvoice) { @@ -1103,8 +1104,6 @@ public function getCustomerData(Customer $customer, $isLoadSubscriber = false, $ $data['total_spent'] = $this->getLifetimeSales($customer->getId()); $data['currency'] = $this->getBaseCurrencyByWebsiteId($customer->getWebsiteId())->getCurrencyCode(); } - \Zend_Debug::dump($data); - die(); return $data; } From 725ea08db404d2f20c3a0f27d2817b1b8260ce1f Mon Sep 17 00:00:00 2001 From: prime Date: Thu, 28 Jan 2021 17:15:49 +0700 Subject: [PATCH 03/17] Other Update - fix null data --- Helper/EmailMarketing.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index e284c4b..79cf46b 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -1218,11 +1218,11 @@ public function testConnection($appID, $secretKey) $secretKey = $this->getSecretKey(); } - return $this->sendRequest([['data' => $this->getStoreInformation()]], '', $appID, $secretKey, true); + return $this->sendRequest($this->getStoreInformation(), '', $appID, $secretKey, true); } /** - * @return DataObject + * @return array * @throws LocalizedException * @throws NoSuchEntityException */ @@ -1231,7 +1231,7 @@ public function getStoreInformation() $storeObj = $this->storeFactory->create()->load($this->storeManager->getStore()->getId()); $store = $this->storeInfo->getStoreInformationObject($storeObj); - return new DataObject([ + return [ 'name' => $store->getName(), 'phone' => $store->getPhone(), 'countryName' => $store->getCountry(), @@ -1243,7 +1243,7 @@ public function getStoreInformation() 'address1' => $store->getData('street_line1'), 'address2' => $store->getData('street_line2'), 'email' => $this->getConfigData('trans_email/ident_sales/email'), - ]); + ]; } /** From a9817ad35a11c3f588976c4f8254ec3cd83ff97c Mon Sep 17 00:00:00 2001 From: trung Date: Thu, 4 Feb 2021 12:05:56 +0700 Subject: [PATCH 04/17] Other Update - update data multistore --- Helper/EmailMarketing.php | 92 +++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index 79cf46b..5645061 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -34,6 +34,8 @@ use Magento\Customer\Model\CustomerFactory; use Magento\Customer\Model\GroupFactory; use Magento\Customer\Model\Metadata\ElementFactory; +use Magento\Directory\Model\Currency; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Helper\Context; use Magento\Framework\DataObject; use Magento\Framework\Encryption\EncryptorInterface; @@ -65,6 +67,7 @@ use Magento\Sales\Model\Order\Config as OrderConfig; use Magento\Store\Model\Information; use Magento\Store\Model\StoreFactory; +use Magento\Directory\Model\CountryFactory; /** * Class EmailMarketing @@ -226,6 +229,11 @@ class EmailMarketing extends Data */ protected $storeFactory; + /** + * @var CountryFactory + */ + protected $countryFactory; + /** * EmailMarketing constructor. * @@ -254,6 +262,7 @@ class EmailMarketing extends Data * @param LoggerInterface $logger * @param Information $storeInfo * @param StoreFactory $storeFactory + * @param CountryFactory $countryFactory */ public function __construct( Context $context, @@ -280,7 +289,8 @@ public function __construct( Config $addressConfig, LoggerInterface $logger, Information $storeInfo, - StoreFactory $storeFactory + StoreFactory $storeFactory, + CountryFactory $countryFactory ) { parent::__construct($context, $objectManager, $storeManager); @@ -306,10 +316,11 @@ public function __construct( $this->_addressConfig = $addressConfig; $this->storeInfo = $storeInfo; $this->storeFactory = $storeFactory; + $this->countryFactory = $countryFactory; } /** - * @return \Magento\Framework\HTTP\Client\Curl + * @return Curl */ public function initCurl() { @@ -623,7 +634,7 @@ public function getOrderViewUrl($storeId, $orderId, $path = 'sales/order/view') */ public function getACEData($quote) { - $isActive = (bool)$quote->getIsActive(); + $isActive = (bool) $quote->getIsActive(); $quoteCompletedAt = null; $updatedAt = $this->getQuoteUpdatedAt($quote->getId()); @@ -636,11 +647,11 @@ public function getACEData($quote) } return [ - 'id' => (int)$quote->getId(), + 'id' => (int) $quote->getId(), 'email' => $quote->getCustomerEmail(), 'completed_at' => $quoteCompletedAt, 'customer' => [ - 'id' => (int)$quote->getCustomerId(), + 'id' => (int) $quote->getCustomerId(), 'email' => $quote->getCustomerEmail(), 'name' => $this->getCustomerName($quote), 'first_name' => $quote->getCustomerFirstname(), @@ -713,7 +724,7 @@ public function getShipmentOrCreditmemoItems($object) 'product_id' => $orderItem->getProductId(), 'sku' => $orderItem->getSku(), 'quantity' => $item->getQty(), - 'price' => (float)$item->getBasePrice() + 'price' => (float) $item->getBasePrice() ]; continue; @@ -723,7 +734,7 @@ public function getShipmentOrCreditmemoItems($object) $items[$orderItem->getParentItemId()]['variant_title'] = $item->getName(); $items[$orderItem->getParentItemId()]['variant_image'] = $this->getProductImage($product); $items[$orderItem->getParentItemId()]['variant_id'] = $orderItem->getProductId(); - $items[$orderItem->getParentItemId()]['variant_price'] = (float)$item->getBasePrice(); + $items[$orderItem->getParentItemId()]['variant_price'] = (float) $item->getBasePrice(); continue; } @@ -734,7 +745,7 @@ public function getShipmentOrCreditmemoItems($object) 'name' => $productType === 'configurable' ? $this->getItemOptions($orderItem) : $item->getName(), 'title' => $item->getName(), - 'price' => (float)$item->getBasePrice(), + 'price' => (float) $item->getBasePrice(), 'quantity' => $item->getQty(), 'sku' => $item->getSku(), 'product_id' => $item->getProductId(), @@ -848,8 +859,8 @@ public function getCartItems($object) 'type' => $productType, 'title' => $item->getName(), 'name' => $name, - 'price' => (float)$item->getBasePrice(), - 'quantity' => (int)($isQuote ? $item->getQty() : $item->getQtyOrdered()), + 'price' => (float) $item->getBasePrice(), + 'quantity' => (int) ($isQuote ? $item->getQty() : $item->getQtyOrdered()), 'sku' => $item->getSku(), 'product_id' => $item->getProductId(), 'image' => $this->getProductImage($product), @@ -868,7 +879,7 @@ public function getCartItems($object) $itemRequest['variant_title'] = $child->getName(); $itemRequest['variant_image'] = $this->getProductImage($product); $itemRequest['variant_id'] = $child->getProductId(); - $itemRequest['variant_price'] = (float)$child->getBasePrice(); + $itemRequest['variant_price'] = (float) $child->getBasePrice(); } if ($isBundle) { @@ -878,8 +889,8 @@ public function getCartItems($object) 'image' => $this->getProductImage($product), 'product_id' => $child->getProductId(), 'sku' => $child->getSku(), - 'quantity' => (int)($isQuote ? $child->getQty() : $child->getQtyOrdered()), - 'price' => (float)$child->getBasePrice() + 'quantity' => (int) ($isQuote ? $child->getQty() : $child->getQtyOrdered()), + 'price' => (float) $child->getBasePrice() ]; } } @@ -960,7 +971,9 @@ public function setHeaders($data, $url = '', $appID = '', $secretKey = '', $isTe $this->url = $url; - $body = self::jsonEncode(['data' => $data]); + $body = self::jsonEncode(['data' => $data]); + \Zend_Debug::dump($data); + die; $storeId = $this->storeId ?: $this->getStoreId(); $secretKey = $secretKey ?: $this->getSecretKey($storeId); $generatedHash = base64_encode(hash_hmac('sha256', $body, $secretKey, true)); @@ -1035,7 +1048,7 @@ public function deleteQuote($id, $storeId) */ public function isSubscriber($subscriberStatus) { - return (int)$subscriberStatus === Subscriber::STATUS_SUBSCRIBED; + return (int) $subscriberStatus === Subscriber::STATUS_SUBSCRIBED; } /** @@ -1223,37 +1236,50 @@ public function testConnection($appID, $secretKey) /** * @return array - * @throws LocalizedException - * @throws NoSuchEntityException */ public function getStoreInformation() { - $storeObj = $this->storeFactory->create()->load($this->storeManager->getStore()->getId()); - $store = $this->storeInfo->getStoreInformationObject($storeObj); + $storeId = $this->_request->getParam('store'); + $websiteId = $this->_request->getParam('website'); - return [ - 'name' => $store->getName(), - 'phone' => $store->getPhone(), - 'countryName' => $store->getCountry(), - 'countryCode' => $store->getCountryId(), - 'city' => $store->getCity(), - 'timezone' => $this->getConfigData('general/locale/timezone'), - 'zip' => $store->getPostcode(), - 'currency' => $this->getConfigData('currency/options/default'), - 'address1' => $store->getData('street_line1'), - 'address2' => $store->getData('street_line2'), - 'email' => $this->getConfigData('trans_email/ident_sales/email'), + if ($storeId) { + $scope = ScopeInterface::SCOPE_STORES; + } elseif ($websiteId) { + $scope = ScopeInterface::SCOPE_WEBSITES; + } else { + $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT; + } + + $info = [ + 'name' => $this->getConfigData(Information::XML_PATH_STORE_INFO_NAME, $scope), + 'phone' => $this->getConfigData(Information::XML_PATH_STORE_INFO_PHONE, $scope), + 'countryCode' => $this->getConfigData(Information::XML_PATH_STORE_INFO_COUNTRY_CODE, $scope), + 'city' => $this->getConfigData(Information::XML_PATH_STORE_INFO_CITY, $scope), + 'timezone' => $this->_localeDate->getConfigTimezone(), + 'zip' => $this->getConfigData(Information::XML_PATH_STORE_INFO_POSTCODE, $scope), + 'currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_DEFAULT), + 'base_currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_BASE), + 'address1' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE1, $scope), + 'address2' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE2, $scope), + 'email' => $this->getConfigData('trans_email/ident_general/email') ]; + + if ($info['countryCode']) { + $info['countryName'] = $this->countryFactory->create()->loadByCode($info['countryCode'])->getName(); + } + + return $info; } /** * @param string $path + * @param string $scope * * @return mixed */ - public function getConfigData(string $path) + public function getConfigData(string $path, $scope = ScopeInterface::SCOPE_STORES) { - return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORES); + return $this->scopeConfig->getValue($path, $scope); } /** From 8c5400d2933fd4498b80f95de6aaa727bdf07da0 Mon Sep 17 00:00:00 2001 From: trung Date: Thu, 4 Feb 2021 13:47:15 +0700 Subject: [PATCH 05/17] Other Update - update data multistore --- Helper/EmailMarketing.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index 5645061..4096fae 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -971,9 +971,7 @@ public function setHeaders($data, $url = '', $appID = '', $secretKey = '', $isTe $this->url = $url; - $body = self::jsonEncode(['data' => $data]); - \Zend_Debug::dump($data); - die; + $body = self::jsonEncode(['data' => $data]); $storeId = $this->storeId ?: $this->getStoreId(); $secretKey = $secretKey ?: $this->getSecretKey($storeId); $generatedHash = base64_encode(hash_hmac('sha256', $body, $secretKey, true)); @@ -1241,6 +1239,7 @@ public function getStoreInformation() { $storeId = $this->_request->getParam('store'); $websiteId = $this->_request->getParam('website'); + $scopeCode = $storeId ?: $websiteId ?: null; if ($storeId) { $scope = ScopeInterface::SCOPE_STORES; @@ -1251,16 +1250,16 @@ public function getStoreInformation() } $info = [ - 'name' => $this->getConfigData(Information::XML_PATH_STORE_INFO_NAME, $scope), - 'phone' => $this->getConfigData(Information::XML_PATH_STORE_INFO_PHONE, $scope), - 'countryCode' => $this->getConfigData(Information::XML_PATH_STORE_INFO_COUNTRY_CODE, $scope), - 'city' => $this->getConfigData(Information::XML_PATH_STORE_INFO_CITY, $scope), + 'name' => $this->getConfigData(Information::XML_PATH_STORE_INFO_NAME, $scope, $scopeCode), + 'phone' => $this->getConfigData(Information::XML_PATH_STORE_INFO_PHONE, $scope, $scopeCode), + 'countryCode' => $this->getConfigData(Information::XML_PATH_STORE_INFO_COUNTRY_CODE, $scope, $scopeCode), + 'city' => $this->getConfigData(Information::XML_PATH_STORE_INFO_CITY, $scope, $scopeCode), 'timezone' => $this->_localeDate->getConfigTimezone(), - 'zip' => $this->getConfigData(Information::XML_PATH_STORE_INFO_POSTCODE, $scope), + 'zip' => $this->getConfigData(Information::XML_PATH_STORE_INFO_POSTCODE, $scope, $scopeCode), 'currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_DEFAULT), 'base_currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_BASE), - 'address1' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE1, $scope), - 'address2' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE2, $scope), + 'address1' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE1, $scope, $scopeCode), + 'address2' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE2, $scope, $scopeCode), 'email' => $this->getConfigData('trans_email/ident_general/email') ]; @@ -1274,12 +1273,13 @@ public function getStoreInformation() /** * @param string $path * @param string $scope + * @param null $scopeCode * * @return mixed */ - public function getConfigData(string $path, $scope = ScopeInterface::SCOPE_STORES) + public function getConfigData(string $path, $scope = ScopeInterface::SCOPE_STORES, $scopeCode = null) { - return $this->scopeConfig->getValue($path, $scope); + return $this->scopeConfig->getValue($path, $scope, $scopeCode); } /** From 6e47cddb5acff9d370841cb520c2dd03e4786977 Mon Sep 17 00:00:00 2001 From: trung Date: Thu, 4 Feb 2021 14:06:14 +0700 Subject: [PATCH 06/17] Other Update - update timezone data multistore --- Helper/EmailMarketing.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index 4096fae..b38d9d9 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -650,6 +650,10 @@ public function getACEData($quote) 'id' => (int) $quote->getId(), 'email' => $quote->getCustomerEmail(), 'completed_at' => $quoteCompletedAt, + 'timezone' => $this->_localeDate->getConfigTimezone( + ScopeInterface::SCOPE_STORE, + $quote->getStoreId() + ), 'customer' => [ 'id' => (int) $quote->getCustomerId(), 'email' => $quote->getCustomerEmail(), @@ -1254,7 +1258,7 @@ public function getStoreInformation() 'phone' => $this->getConfigData(Information::XML_PATH_STORE_INFO_PHONE, $scope, $scopeCode), 'countryCode' => $this->getConfigData(Information::XML_PATH_STORE_INFO_COUNTRY_CODE, $scope, $scopeCode), 'city' => $this->getConfigData(Information::XML_PATH_STORE_INFO_CITY, $scope, $scopeCode), - 'timezone' => $this->_localeDate->getConfigTimezone(), + 'timezone' => $this->_localeDate->getConfigTimezone($scope, $scopeCode), 'zip' => $this->getConfigData(Information::XML_PATH_STORE_INFO_POSTCODE, $scope, $scopeCode), 'currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_DEFAULT), 'base_currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_BASE), From 64f3d1acbfcdd61e6d0c1a6e6418dadd23c28dbd Mon Sep 17 00:00:00 2001 From: Jacker Date: Mon, 8 Feb 2021 10:04:49 +0700 Subject: [PATCH 07/17] Fix bug sync order by website id --- Controller/Adminhtml/Smtp/Sync/EstimateOrder.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Controller/Adminhtml/Smtp/Sync/EstimateOrder.php b/Controller/Adminhtml/Smtp/Sync/EstimateOrder.php index ec08528..df6ec97 100644 --- a/Controller/Adminhtml/Smtp/Sync/EstimateOrder.php +++ b/Controller/Adminhtml/Smtp/Sync/EstimateOrder.php @@ -59,7 +59,17 @@ public function __construct( */ public function prepareCollection() { - return $this->orderCollectionFactory->create(); + $orderCollection = $this->orderCollectionFactory->create(); + $storeTable = $orderCollection->getTable('store'); + $orderCollection->getSelect()->join( + ['store_table' => $storeTable], + 'main_table.entity_id = store_table.store_id', + [ + 'store_table.website_id' + ] + ); + + return $orderCollection; } /** From f53d62c2aa6be6d273ebbeff5e849f9aa4825c60 Mon Sep 17 00:00:00 2001 From: Jacker Date: Tue, 16 Feb 2021 20:41:50 +0700 Subject: [PATCH 08/17] Fix bug sync order by website and improre get product on order items --- .../Adminhtml/Smtp/Sync/AbstractEstimate.php | 14 ++++++++++++-- Controller/Adminhtml/Smtp/Sync/EstimateOrder.php | 6 ++++-- Helper/EmailMarketing.php | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Controller/Adminhtml/Smtp/Sync/AbstractEstimate.php b/Controller/Adminhtml/Smtp/Sync/AbstractEstimate.php index 47647a6..665e299 100644 --- a/Controller/Adminhtml/Smtp/Sync/AbstractEstimate.php +++ b/Controller/Adminhtml/Smtp/Sync/AbstractEstimate.php @@ -49,6 +49,16 @@ abstract class AbstractEstimate extends Action */ protected $emailMarketing; + /** + * @var string + */ + protected $websiteIdField = 'website_id'; + + /** + * @var string + */ + protected $storeIdField = 'store_id'; + /** * AbstractEstimate constructor. * @@ -79,11 +89,11 @@ public function execute() $storeId = $this->getRequest()->getParam('storeId'); $websiteId = $this->getRequest()->getParam('websiteId'); if ($storeId) { - $collection->addFieldToFilter('store_id', $storeId); + $collection->addFieldToFilter($this->storeIdField, $storeId); } if ($websiteId) { - $collection->addFieldToFilter('website_id', $websiteId); + $collection->addFieldToFilter($this->websiteIdField, $websiteId); } $ids = $collection->getAllIds(); diff --git a/Controller/Adminhtml/Smtp/Sync/EstimateOrder.php b/Controller/Adminhtml/Smtp/Sync/EstimateOrder.php index df6ec97..928b272 100644 --- a/Controller/Adminhtml/Smtp/Sync/EstimateOrder.php +++ b/Controller/Adminhtml/Smtp/Sync/EstimateOrder.php @@ -61,11 +61,13 @@ public function prepareCollection() { $orderCollection = $this->orderCollectionFactory->create(); $storeTable = $orderCollection->getTable('store'); + $this->websiteIdField = 'store_table.website_id'; + $this->storeIdField = 'main_table.store_id'; $orderCollection->getSelect()->join( ['store_table' => $storeTable], - 'main_table.entity_id = store_table.store_id', + 'main_table.store_id = store_table.store_id', [ - 'store_table.website_id' + $this->websiteIdField ] ); diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index b38d9d9..044c8f3 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -844,7 +844,7 @@ public function getCartItems($object) /** * @var Product $product */ - $product = $item->getProduct(); + $product = $item->getProduct() ?: new DataObject([]); $productType = $item->getData('product_type'); $bundleItems = []; @@ -868,7 +868,7 @@ public function getCartItems($object) 'sku' => $item->getSku(), 'product_id' => $item->getProductId(), 'image' => $this->getProductImage($product), - 'frontend_link' => $product->getProductUrl() + 'frontend_link' => $product->getProductUrl() ?: '#' ]; if ($isQuote) { From 930a4e36ab8d70bf125ad2688f1327b0a16ce114 Mon Sep 17 00:00:00 2001 From: trung Date: Tue, 23 Feb 2021 16:33:50 +0700 Subject: [PATCH 09/17] Feature Update - update test connection api url, add newsletter sync feature --- .../System/Config/SyncSubscriber.php | 90 +++++ .../Smtp/Sync/EstimateSubscriber.php | 82 ++++ Controller/Adminhtml/Smtp/Sync/Subscriber.php | 154 ++++++++ Helper/EmailMarketing.php | 15 +- Model/Config/Source/Newsletter.php | 55 +++ etc/adminhtml/system.xml | 374 +++++++++--------- etc/config.xml | 76 ++-- view/adminhtml/web/js/sync/subscriber.js | 46 +++ 8 files changed, 673 insertions(+), 219 deletions(-) create mode 100755 Block/Adminhtml/System/Config/SyncSubscriber.php create mode 100755 Controller/Adminhtml/Smtp/Sync/EstimateSubscriber.php create mode 100755 Controller/Adminhtml/Smtp/Sync/Subscriber.php create mode 100755 Model/Config/Source/Newsletter.php mode change 100644 => 100755 etc/adminhtml/system.xml mode change 100644 => 100755 etc/config.xml create mode 100755 view/adminhtml/web/js/sync/subscriber.js diff --git a/Block/Adminhtml/System/Config/SyncSubscriber.php b/Block/Adminhtml/System/Config/SyncSubscriber.php new file mode 100755 index 0000000..da61c07 --- /dev/null +++ b/Block/Adminhtml/System/Config/SyncSubscriber.php @@ -0,0 +1,90 @@ +getUrl('adminhtml/smtp_sync/estimatesubscriber', ['_current' => true]); + } + + /** + * @return mixed + */ + public function getWebsiteId() + { + return $this->getRequest()->getParam('website'); + } + + /** + * @return mixed + */ + public function getStoreId() + { + return $this->getRequest()->getParam('store'); + } + + /** + * @return mixed + */ + public function getSyncSuccessMessage() + { + return __('Subscriber synchronization has been completed.'); + } + + /** + * @return string + */ + public function getElementId() + { + return 'mp-sync-subscriber'; + } + + /** + * @return string + */ + public function getComponent() + { + return 'Mageplaza_Smtp/js/sync/subscriber'; + } + + /** + * @return bool + */ + public function isRenderCss() + { + return true; + } +} diff --git a/Controller/Adminhtml/Smtp/Sync/EstimateSubscriber.php b/Controller/Adminhtml/Smtp/Sync/EstimateSubscriber.php new file mode 100755 index 0000000..52e0b5b --- /dev/null +++ b/Controller/Adminhtml/Smtp/Sync/EstimateSubscriber.php @@ -0,0 +1,82 @@ +subscriberCollectionFactory = $subscriberCollectionFactory; + + parent::__construct($context, $emailMarketing); + } + + /** + * @return AbstractCollection|Collection + */ + public function prepareCollection() + { + $collection = $this->subscriberCollectionFactory->create(); + + if ($this->emailMarketing->getSubscriberConfig() === Newsletter::SUBSCRIBED) { + $collection->addFieldToFilter('subscriber_status', ['eq' => Subscriber::STATUS_SUBSCRIBED]); + } + + return $collection; + } + + /** + * @return Phrase + */ + public function getZeroMessage() + { + return __('No subscriber to synchronize.'); + } +} diff --git a/Controller/Adminhtml/Smtp/Sync/Subscriber.php b/Controller/Adminhtml/Smtp/Sync/Subscriber.php new file mode 100755 index 0000000..e285515 --- /dev/null +++ b/Controller/Adminhtml/Smtp/Sync/Subscriber.php @@ -0,0 +1,154 @@ +helperEmailMarketing = $helperEmailMarketing; + $this->subscriberCollectionFactory = $subscriberCollectionFactory; + $this->customerCollectionFactory = $customerCollectionFactory; + parent::__construct($context); + } + + /** + * @return ResponseInterface|ResultInterface + */ + public function execute() + { + $result = []; + + try { + $collection = $this->subscriberCollectionFactory->create(); + + if ($this->helperEmailMarketing->getSubscriberConfig() === Newsletter::SUBSCRIBED) { + $collection->addFieldToFilter('subscriber_status', ['eq' => ModelSubscriber::STATUS_SUBSCRIBED]); + } + + $data = []; + + foreach ($collection as $subscriber) { + switch ($subscriber->getSubscriberStatus()) { + case ModelSubscriber::STATUS_SUBSCRIBED: + $status = self::SUB; + break; + case ModelSubscriber::STATUS_UNSUBSCRIBED: + $status = self::UNSUB; + break; + default: + $status = self::NOTSUB; + break; + } + + if ($subscriber->getCustomerId()) { + $customerCollection = $this->customerCollectionFactory->create(); + $customerCollection->addFieldToFilter('entity_id', ['eq' => $subscriber->getCustomerId()]); + + foreach ($customerCollection as $customer) { + $customerData = $this->helperEmailMarketing->getCustomerData( + $customer, + false, + true + ); + $customerData['status'] = $status; + $customerData['tags'] = 'newsletter'; + $customerData['isSubscriber'] = true; + $data[] = $customerData; + } + + } else { + $data[] = [ + 'email' => $subscriber->getSubscriberEmail(), + 'status' => $status, + 'source' => 'Magento', + 'tags' => 'newsletter', + 'isSubscriber' => true + ]; + } + } + + $result['status'] = true; + $result['total'] = count($collection); + $this->helperEmailMarketing->syncCustomers($data); + + } catch (Exception $e) { + $result['status'] = false; + $result['message'] = $e->getMessage(); + } + + return $this->getResponse()->representJson(EmailMarketing::jsonEncode($result)); + } +} diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index 044c8f3..c621da6 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -77,7 +77,7 @@ class EmailMarketing extends Data { const IS_SYNCED_ATTRIBUTE = 'mp_smtp_is_synced'; - const APP_URL = 'https://app.avada.io/app/api/v1/checkouts'; + const APP_URL = 'https://app.avada.io/app/api/v1/connects'; const CUSTOMER_URL = 'https://app.avada.io/app/api/v1/customers'; const ORDER_URL = 'https://app.avada.io/app/api/v1/orders'; const ORDER_COMPLETE_URL = 'https://app.avada.io/app/api/v1/orders/complete'; @@ -1118,6 +1118,7 @@ public function getCustomerData(Customer $customer, $isLoadSubscriber = false, $ $data['last_order_id'] = $lastOrderId; $data['total_spent'] = $this->getLifetimeSales($customer->getId()); $data['currency'] = $this->getBaseCurrencyByWebsiteId($customer->getWebsiteId())->getCurrencyCode(); + $this->orderCollection->getSelect()->reset(\Zend_Db_Select::WHERE); } return $data; @@ -1233,7 +1234,7 @@ public function testConnection($appID, $secretKey) $secretKey = $this->getSecretKey(); } - return $this->sendRequest($this->getStoreInformation(), '', $appID, $secretKey, true); + return $this->sendRequest($this->getStoreInformation(), '', $appID, $secretKey); } /** @@ -1355,4 +1356,14 @@ public function isSyncedCustomer() { return $this->isSyncCustomer; } + + /** + * @param null $storeId + * + * @return mixed + */ + public function getSubscriberConfig($storeId = null) + { + return $this->getEmailMarketingConfig('newsletter_subscriber', $storeId); + } } diff --git a/Model/Config/Source/Newsletter.php b/Model/Config/Source/Newsletter.php new file mode 100755 index 0000000..cf2be84 --- /dev/null +++ b/Model/Config/Source/Newsletter.php @@ -0,0 +1,55 @@ + self::ALL, + 'label' => __('All') + ], + [ + 'value' => self::SUBSCRIBED, + 'label' => __('Only Subscribed') + ] + ]; + + return $options; + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml old mode 100644 new mode 100755 index 00cc0e5..6984dd3 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,182 +1,192 @@ - - - -
- - mageplaza - Mageplaza_Smtp::configuration - - - - - Magento\Config\Model\Config\Source\Yesno - - It helps to reduce abandonment cart with One Step Checkout. Fully compatible with Abandoned Cart Email]]> - - - - - Magento\Config\Model\Config\Source\Yesno - It will log all sent emails, you can preview it and schedule clean up. - - - - validate-number validate-zero-or-greater validate-digits - Day(s). If empty or zero, the Email log will not be cleaned. - - 1 - - - - - - For the email having the same pattern format with this main pattern, it can not receive email from the system.
- For example: Enter the pattern: /^[0-9][a-z0-9\$\%\&]+@[a-z]+\.[a-z]{2,}$/ means that email format must start with number, the following characters can be normal text, number or special character ($, %, &). The domain after @ with normal-text characters will not receive email from system. For instance: 1abc@example.com
- For more details of writing email pattern, please see it here.]]> -
-
-
- - - - - Support Host name and IP Address - Mageplaza\Smtp\Block\Adminhtml\System\Config\Host - - - - Default ports: 25, 465, or 587. Port 465 (SSL required), Port 587 (TLS required) - - - - Mageplaza\Smtp\Model\Config\Source\Protocol - We recommend use security connections: SSL or TLS. Secure Socket Layer (SSL), Transport Layer Security (TLS) protocols. - - - - Mageplaza\Smtp\Model\Config\Source\Authentication - - - - - - - Magento\Config\Model\Config\Backend\Encrypted - - - - Leave empty to ignore it. - validate-email - - - - - - Magento\Config\Model\Config\Source\Email\Identity - - - - Enter your email and click Test Now button to test the configuration.
- Read:
- - FAQs
- - Connection timed out -
-

]]> -
-
- - - Test Now - adminhtml/smtp/test - Mageplaza\Smtp\Block\Adminhtml\System\Config\Button - -
-
- - - - - Magento\Config\Model\Config\Source\Yesno - If Enable, Magento will not delivery any email to receiver. This is useful for developers. - - -
-
- - mageplaza - Mageplaza_Smtp::email_marketing - - - - - Magento\Config\Model\Config\Source\Yesno - Terms & Conditions and Data processing agreement.]]> - - - - here.]]> - - 1 - - - - - Magento\Config\Model\Config\Backend\Encrypted - - 1 - - - - - Test connection - adminhtml/smtp/testconnection - Mageplaza\Smtp\Block\Adminhtml\System\Config\TestConnection - - 1 - - - - - - - Synchronize Customers - adminhtml/smtp_sync/customer - Mageplaza\Smtp\Block\Adminhtml\System\Config\SyncCustomer - - - 1 - - - - Synchronize Orders - adminhtml/smtp_sync/order - Mageplaza\Smtp\Block\Adminhtml\System\Config\SyncOrder - - - 1 - - - -
-
-
\ No newline at end of file + + + +
+ + mageplaza + Mageplaza_Smtp::configuration + + + + + Magento\Config\Model\Config\Source\Yesno + + It helps to reduce abandonment cart with One Step Checkout. Fully compatible with Abandoned Cart Email]]> + + + + + Magento\Config\Model\Config\Source\Yesno + It will log all sent emails, you can preview it and schedule clean up. + + + + validate-number validate-zero-or-greater validate-digits + Day(s). If empty or zero, the Email log will not be cleaned. + + 1 + + + + + + For the email having the same pattern format with this main pattern, it can not receive email from the system.
+ For example: Enter the pattern: /^[0-9][a-z0-9\$\%\&]+@[a-z]+\.[a-z]{2,}$/ means that email format must start with number, the following characters can be normal text, number or special character ($, %, &). The domain after @ with normal-text characters will not receive email from system. For instance: 1abc@example.com
+ For more details of writing email pattern, please see it here.]]> +
+
+
+ + + + + Support Host name and IP Address + Mageplaza\Smtp\Block\Adminhtml\System\Config\Host + + + + Default ports: 25, 465, or 587. Port 465 (SSL required), Port 587 (TLS required) + + + + Mageplaza\Smtp\Model\Config\Source\Protocol + We recommend use security connections: SSL or TLS. Secure Socket Layer (SSL), Transport Layer Security (TLS) protocols. + + + + Mageplaza\Smtp\Model\Config\Source\Authentication + + + + + + + Magento\Config\Model\Config\Backend\Encrypted + + + + Leave empty to ignore it. + validate-email + + + + + + Magento\Config\Model\Config\Source\Email\Identity + + + + Enter your email and click Test Now button to test the configuration.
+ Read:
+ - FAQs
+ - Connection timed out +
+

]]> +
+
+ + + Test Now + adminhtml/smtp/test + Mageplaza\Smtp\Block\Adminhtml\System\Config\Button + +
+
+ + + + + Magento\Config\Model\Config\Source\Yesno + If Enable, Magento will not delivery any email to receiver. This is useful for developers. + + +
+
+ + mageplaza + Mageplaza_Smtp::email_marketing + + + + + Magento\Config\Model\Config\Source\Yesno + Terms & Conditions and Data processing agreement.]]> + + + + Mageplaza\Smtp\Model\Config\Source\Newsletter + + 1 + + + + + here.]]> + + 1 + + + + + Magento\Config\Model\Config\Backend\Encrypted + + 1 + + + + + Test connection + adminhtml/smtp/testconnection + Mageplaza\Smtp\Block\Adminhtml\System\Config\TestConnection + + 1 + + + + + + + Synchronize Customers + adminhtml/smtp_sync/customer + Mageplaza\Smtp\Block\Adminhtml\System\Config\SyncCustomer + + + + Synchronize Orders + adminhtml/smtp_sync/order + Mageplaza\Smtp\Block\Adminhtml\System\Config\SyncOrder + + + + Synchronize Subscribers + adminhtml/smtp_sync/subscriber + Mageplaza\Smtp\Block\Adminhtml\System\Config\SyncSubscriber + + + 1 + + + +
+
+
diff --git a/etc/config.xml b/etc/config.xml old mode 100644 new mode 100755 index 0b4902f..35b776b --- a/etc/config.xml +++ b/etc/config.xml @@ -1,35 +1,41 @@ - - - - - - 1 - - - 0 - 1 - 10 - - - - + + + + + + 1 + + + 0 + 1 + 10 + + + + + 0 + 0 + + + + diff --git a/view/adminhtml/web/js/sync/subscriber.js b/view/adminhtml/web/js/sync/subscriber.js new file mode 100755 index 0000000..664b893 --- /dev/null +++ b/view/adminhtml/web/js/sync/subscriber.js @@ -0,0 +1,46 @@ +/** + * Mageplaza + * + * NOTICE OF LICENSE + * + * This source file is subject to the Mageplaza.com license that is + * available through the world-wide-web at this URL: + * https://www.mageplaza.com/LICENSE.txt + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this extension to newer + * version in the future. + * + * @category Mageplaza + * @package Mageplaza_Smtp + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) + * @license https://www.mageplaza.com/LICENSE.txt + */ +define([ + 'jquery', + 'Mageplaza_Smtp/js/model/sync' +], function ($, Sync) { + 'use strict'; + + $.widget('mageplaza.syncsubscriber', { + options: { + ajaxUrl: '', + websiteId: '', + storeId: '', + estimateUrl: '', + buttonElement: '#email_marketing_general_synchronization_sync_subscriber', + prefix: '#mp-sync-subscriber' + }, + _create: function () { + var self = this; + + $(this.options.buttonElement).click(function (e) { + e.preventDefault(); + Sync.process(self.options); + }); + }, + }); + + return $.mageplaza.syncsubscriber; +}); From 20c475618c834cb5864c1039aad408cc2bb77b78 Mon Sep 17 00:00:00 2001 From: trung Date: Tue, 23 Feb 2021 16:42:02 +0700 Subject: [PATCH 10/17] Other Update - fix wrong order count when sync customer, newsletter --- Helper/EmailMarketing.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index c621da6..a664079 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -844,7 +844,7 @@ public function getCartItems($object) /** * @var Product $product */ - $product = $item->getProduct() ?: new DataObject([]); + $product = $item->getProduct() ?: new DataObject([]); $productType = $item->getData('product_type'); $bundleItems = []; @@ -1110,15 +1110,18 @@ public function getCustomerData(Customer $customer, $isLoadSubscriber = false, $ } if ($isUpdateOrder) { - $orderCollectionByCustomer = $this->orderCollection->addFieldToFilter('customer_id', $customer->getId()); - $size = $orderCollectionByCustomer->getSize(); - $lastOrderId = $orderCollectionByCustomer->addOrder('entity_id')->getFirstItem()->getId(); + $orderCollectionByCustomer = clone $this->orderCollection; + $_orderCollectionByCustomer = $orderCollectionByCustomer->addFieldToFilter( + 'customer_id', + $customer->getId() + ); + $size = $_orderCollectionByCustomer->getSize(); + $lastOrderId = $_orderCollectionByCustomer->addOrder('entity_id')->getFirstItem()->getId(); $data['orders_count'] = $size; $data['last_order_id'] = $lastOrderId; $data['total_spent'] = $this->getLifetimeSales($customer->getId()); $data['currency'] = $this->getBaseCurrencyByWebsiteId($customer->getWebsiteId())->getCurrencyCode(); - $this->orderCollection->getSelect()->reset(\Zend_Db_Select::WHERE); } return $data; From 81a47bb52d79cc68fd9e1ba3632d0cb3ffc2a096 Mon Sep 17 00:00:00 2001 From: trung Date: Wed, 24 Feb 2021 10:57:57 +0700 Subject: [PATCH 11/17] Other Update - remove display currency, show error message if connect failed --- Controller/Adminhtml/Smtp/TestConnection.php | 2 +- Helper/EmailMarketing.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Controller/Adminhtml/Smtp/TestConnection.php b/Controller/Adminhtml/Smtp/TestConnection.php index a11fc65..7379608 100644 --- a/Controller/Adminhtml/Smtp/TestConnection.php +++ b/Controller/Adminhtml/Smtp/TestConnection.php @@ -78,7 +78,7 @@ public function execute() } catch (Exception $e) { $result = [ 'status' => false, - 'content' => __('Can\'t connect to the email marketing app. Please check the app id and secret key.') + 'content' => __('Can\'t connect to the email marketing app. ' . $e->getMessage()) ]; } diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index a664079..485c1db 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -1264,8 +1264,7 @@ public function getStoreInformation() 'city' => $this->getConfigData(Information::XML_PATH_STORE_INFO_CITY, $scope, $scopeCode), 'timezone' => $this->_localeDate->getConfigTimezone($scope, $scopeCode), 'zip' => $this->getConfigData(Information::XML_PATH_STORE_INFO_POSTCODE, $scope, $scopeCode), - 'currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_DEFAULT), - 'base_currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_BASE), + 'currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_BASE), 'address1' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE1, $scope, $scopeCode), 'address2' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE2, $scope, $scopeCode), 'email' => $this->getConfigData('trans_email/ident_general/email') From 81c94db484260aac46916ba90605b9d1df9dcbe9 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 24 Feb 2021 15:17:37 +0700 Subject: [PATCH 12/17] fix xss preview email --- view/adminhtml/web/js/grid/columns/actions.js | 121 +++++++++--------- 1 file changed, 64 insertions(+), 57 deletions(-) diff --git a/view/adminhtml/web/js/grid/columns/actions.js b/view/adminhtml/web/js/grid/columns/actions.js index 8b82647..2c3f2a4 100644 --- a/view/adminhtml/web/js/grid/columns/actions.js +++ b/view/adminhtml/web/js/grid/columns/actions.js @@ -1,57 +1,64 @@ -/** - * Mageplaza - * - * NOTICE OF LICENSE - * - * This source file is subject to the Mageplaza.com license sliderConfig is - * available through the world-wide-web at this URL: - * https://www.mageplaza.com/LICENSE.txt - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this extension to newer - * version in the future. - * - * @category Mageplaza - * @package Mageplaza_Smtp - * @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/) - * @license https://www.mageplaza.com/LICENSE.txt - */ - -define([ - 'jquery', - 'Magento_Ui/js/grid/columns/actions', - 'Magento_Ui/js/modal/modal' -], function ($, Column) { - 'use strict'; - - return Column.extend({ - modal: {}, - - /** - * @inheritDoc - */ - defaultCallback: function (actionIndex, recordId, action) { - if (actionIndex !== 'view') { - return this._super(); - } - - if (typeof this.modal[action.rowIndex] === 'undefined') { - var row = this.rows[action.rowIndex], - modalHtml = ''; - this.modal[action.rowIndex] = $('
') - .html(modalHtml) - .modal({ - type: 'slide', - title: row['subject'], - modalClass: 'mpsmtp-modal-email', - innerScroll: true, - buttons: [] - }); - } - - this.modal[action.rowIndex].trigger('openModal'); - } - }); -}); - +/** + * Mageplaza + * + * NOTICE OF LICENSE + * + * This source file is subject to the Mageplaza.com license sliderConfig is + * available through the world-wide-web at this URL: + * https://www.mageplaza.com/LICENSE.txt + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this extension to newer + * version in the future. + * + * @category Mageplaza + * @package Mageplaza_Smtp + * @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/) + * @license https://www.mageplaza.com/LICENSE.txt + */ + +define([ + 'jquery', + 'Magento_Ui/js/grid/columns/actions', + 'Magento_Ui/js/modal/modal' +], function ($, Column) { + 'use strict'; + + function strip(html){ + var doc = new DOMParser().parseFromString(html, 'text/html'); + + return doc.body.textContent || ""; + } + + return Column.extend({ + modal: {}, + + /** + * @inheritDoc + */ + defaultCallback: function (actionIndex, recordId, action) { + if (actionIndex !== 'view') { + return this._super(); + } + + if (typeof this.modal[action.rowIndex] === 'undefined') { + var row = this.rows[action.rowIndex], + modalHtml = ''; + + this.modal[action.rowIndex] = $('
') + .html(modalHtml) + .modal({ + type: 'slide', + title: strip(row['subject']), + modalClass: 'mpsmtp-modal-email', + innerScroll: true, + buttons: [] + }); + } + + this.modal[action.rowIndex].trigger('openModal'); + } + }); +}); + From 51d7b0b6cf7c341480bbdd9f623bdc9069dd7539 Mon Sep 17 00:00:00 2001 From: trung Date: Thu, 25 Feb 2021 14:04:04 +0700 Subject: [PATCH 13/17] Other Update - fix ace error when add to cart --- Helper/EmailMarketing.php | 21 +++++++++++---------- Observer/Quote/SyncQuote.php | 15 +++++++++------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index 485c1db..c73c7d6 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -78,6 +78,7 @@ class EmailMarketing extends Data const IS_SYNCED_ATTRIBUTE = 'mp_smtp_is_synced'; const APP_URL = 'https://app.avada.io/app/api/v1/connects'; + const CHECKOUT_URL = 'https://app.avada.io/app/api/v1/checkouts'; const CUSTOMER_URL = 'https://app.avada.io/app/api/v1/customers'; const ORDER_URL = 'https://app.avada.io/app/api/v1/orders'; const ORDER_COMPLETE_URL = 'https://app.avada.io/app/api/v1/orders/complete'; @@ -1258,16 +1259,16 @@ public function getStoreInformation() } $info = [ - 'name' => $this->getConfigData(Information::XML_PATH_STORE_INFO_NAME, $scope, $scopeCode), - 'phone' => $this->getConfigData(Information::XML_PATH_STORE_INFO_PHONE, $scope, $scopeCode), - 'countryCode' => $this->getConfigData(Information::XML_PATH_STORE_INFO_COUNTRY_CODE, $scope, $scopeCode), - 'city' => $this->getConfigData(Information::XML_PATH_STORE_INFO_CITY, $scope, $scopeCode), - 'timezone' => $this->_localeDate->getConfigTimezone($scope, $scopeCode), - 'zip' => $this->getConfigData(Information::XML_PATH_STORE_INFO_POSTCODE, $scope, $scopeCode), - 'currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_BASE), - 'address1' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE1, $scope, $scopeCode), - 'address2' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE2, $scope, $scopeCode), - 'email' => $this->getConfigData('trans_email/ident_general/email') + 'name' => $this->getConfigData(Information::XML_PATH_STORE_INFO_NAME, $scope, $scopeCode), + 'phone' => $this->getConfigData(Information::XML_PATH_STORE_INFO_PHONE, $scope, $scopeCode), + 'countryCode' => $this->getConfigData(Information::XML_PATH_STORE_INFO_COUNTRY_CODE, $scope, $scopeCode), + 'city' => $this->getConfigData(Information::XML_PATH_STORE_INFO_CITY, $scope, $scopeCode), + 'timezone' => $this->_localeDate->getConfigTimezone($scope, $scopeCode), + 'zip' => $this->getConfigData(Information::XML_PATH_STORE_INFO_POSTCODE, $scope, $scopeCode), + 'currency' => $this->getConfigData(Currency::XML_PATH_CURRENCY_BASE), + 'address1' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE1, $scope, $scopeCode), + 'address2' => $this->getConfigData(Information::XML_PATH_STORE_INFO_STREET_LINE2, $scope, $scopeCode), + 'email' => $this->getConfigData('trans_email/ident_general/email') ]; if ($info['countryCode']) { diff --git a/Observer/Quote/SyncQuote.php b/Observer/Quote/SyncQuote.php index 4ebc251..c6e985a 100644 --- a/Observer/Quote/SyncQuote.php +++ b/Observer/Quote/SyncQuote.php @@ -55,7 +55,7 @@ public function __construct( LoggerInterface $logger ) { $this->helperEmailMarketing = $helperEmailMarketing; - $this->logger = $logger; + $this->logger = $logger; } /** @@ -70,12 +70,12 @@ public function execute(Observer $observer) ) { try { /* @var Quote $quote */ - $quote = $observer->getEvent()->getQuote(); + $quote = $observer->getEvent()->getQuote(); $aceLogData = $quote->getData('mp_smtp_ace_log_data'); - $itemCount = (int)$quote->getItemsCount(); - $isValid = ($itemCount > 0 || ($aceLogData && $itemCount < 1)); + $itemCount = (int) $quote->getItemsCount(); + $isValid = ($itemCount > 0 || ($aceLogData && $itemCount < 1)); if ($isValid) { - $ACEData = $this->helperEmailMarketing->getACEData($quote); + $ACEData = $this->helperEmailMarketing->getACEData($quote); $oldACEData = $aceLogData ? EmailMarketing::jsonDecode($aceLogData) : []; if ($oldACEData !== $ACEData && empty($oldACEData['checkoutCompleted'])) { $resource = $this->helperEmailMarketing->getResourceQuote(); @@ -85,7 +85,10 @@ public function execute(Observer $observer) ['entity_id = ?' => $quote->getId()] ); - $this->helperEmailMarketing->sendRequestWithoutWaitResponse($ACEData); + $this->helperEmailMarketing->sendRequestWithoutWaitResponse( + $ACEData, + EmailMarketing::CHECKOUT_URL + ); } } } catch (Exception $e) { From 7f46424d625eb2ff89f71c3222baf250386ce963 Mon Sep 17 00:00:00 2001 From: trung Date: Thu, 25 Feb 2021 16:39:22 +0700 Subject: [PATCH 14/17] format code --- Controller/Adminhtml/Smtp/Sync/Subscriber.php | 2 +- Controller/Adminhtml/Smtp/TestConnection.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Controller/Adminhtml/Smtp/Sync/Subscriber.php b/Controller/Adminhtml/Smtp/Sync/Subscriber.php index e285515..c3c3bcb 100755 --- a/Controller/Adminhtml/Smtp/Sync/Subscriber.php +++ b/Controller/Adminhtml/Smtp/Sync/Subscriber.php @@ -65,7 +65,7 @@ class Subscriber extends Action protected $customerCollectionFactory; /** - * Customer constructor. + * Subscriber constructor. * * @param Context $context * @param EmailMarketing $helperEmailMarketing diff --git a/Controller/Adminhtml/Smtp/TestConnection.php b/Controller/Adminhtml/Smtp/TestConnection.php index 7379608..ee61ec4 100644 --- a/Controller/Adminhtml/Smtp/TestConnection.php +++ b/Controller/Adminhtml/Smtp/TestConnection.php @@ -78,7 +78,7 @@ public function execute() } catch (Exception $e) { $result = [ 'status' => false, - 'content' => __('Can\'t connect to the email marketing app. ' . $e->getMessage()) + 'content' => __('Can\'t connect to the email marketing app. %1', $e->getMessage()) ]; } From 7d2fbdc94769b04110df7b5b2dc9322cdf3864d4 Mon Sep 17 00:00:00 2001 From: trung Date: Thu, 25 Feb 2021 18:17:19 +0700 Subject: [PATCH 15/17] Feature Update - fix limit 100 record --- Controller/Adminhtml/Smtp/Sync/Subscriber.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Controller/Adminhtml/Smtp/Sync/Subscriber.php b/Controller/Adminhtml/Smtp/Sync/Subscriber.php index c3c3bcb..e8fe648 100755 --- a/Controller/Adminhtml/Smtp/Sync/Subscriber.php +++ b/Controller/Adminhtml/Smtp/Sync/Subscriber.php @@ -93,6 +93,7 @@ public function execute() try { $collection = $this->subscriberCollectionFactory->create(); + $ids = $this->getRequest()->getParam('ids'); if ($this->helperEmailMarketing->getSubscriberConfig() === Newsletter::SUBSCRIBED) { $collection->addFieldToFilter('subscriber_status', ['eq' => ModelSubscriber::STATUS_SUBSCRIBED]); @@ -100,7 +101,9 @@ public function execute() $data = []; - foreach ($collection as $subscriber) { + $subscribers = $collection->addFieldToFilter('entity_id', ['in' => $ids]); + + foreach ($subscribers as $subscriber) { switch ($subscriber->getSubscriberStatus()) { case ModelSubscriber::STATUS_SUBSCRIBED: $status = self::SUB; @@ -141,7 +144,7 @@ public function execute() } $result['status'] = true; - $result['total'] = count($collection); + $result['total'] = count($ids); $this->helperEmailMarketing->syncCustomers($data); } catch (Exception $e) { From 6720446821fd36c9e7b9e0d77ab15c382a57a1a3 Mon Sep 17 00:00:00 2001 From: trung Date: Thu, 25 Feb 2021 18:29:43 +0700 Subject: [PATCH 16/17] Feature Update - fix limit 100 record --- Controller/Adminhtml/Smtp/Sync/Subscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Adminhtml/Smtp/Sync/Subscriber.php b/Controller/Adminhtml/Smtp/Sync/Subscriber.php index e8fe648..a31471c 100755 --- a/Controller/Adminhtml/Smtp/Sync/Subscriber.php +++ b/Controller/Adminhtml/Smtp/Sync/Subscriber.php @@ -101,7 +101,7 @@ public function execute() $data = []; - $subscribers = $collection->addFieldToFilter('entity_id', ['in' => $ids]); + $subscribers = $collection->addFieldToFilter('subscriber_id', ['in' => $ids]); foreach ($subscribers as $subscriber) { switch ($subscriber->getSubscriberStatus()) { From e1792ee69f1613392c152f6096d8f39f5510a101 Mon Sep 17 00:00:00 2001 From: jacker Date: Fri, 26 Feb 2021 10:32:45 +0700 Subject: [PATCH 17/17] Update composer version --- Helper/EmailMarketing.php | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/EmailMarketing.php b/Helper/EmailMarketing.php index c73c7d6..3db6811 100755 --- a/Helper/EmailMarketing.php +++ b/Helper/EmailMarketing.php @@ -1285,7 +1285,7 @@ public function getStoreInformation() * * @return mixed */ - public function getConfigData(string $path, $scope = ScopeInterface::SCOPE_STORES, $scopeCode = null) + public function getConfigData($path, $scope = ScopeInterface::SCOPE_STORES, $scopeCode = null) { return $this->scopeConfig->getValue($path, $scope, $scopeCode); } diff --git a/composer.json b/composer.json index 2c625b4..b385e87 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "mageplaza/module-core": "^1.4.5" }, "type": "magento2-module", - "version": "4.2.1", + "version": "4.3.0", "license": "proprietary", "authors": [ {