diff --git a/Cron/Ecommerce.php b/Cron/Ecommerce.php index 6e0b6d84..57bb6bfb 100644 --- a/Cron/Ecommerce.php +++ b/Cron/Ecommerce.php @@ -81,7 +81,6 @@ public function __construct( public function execute() { - $this->_helper->log(__METHOD__); foreach($this->_storeManager->getStores() as $storeId => $val) { $this->_storeManager->setCurrentStore($storeId); @@ -98,7 +97,6 @@ public function execute() protected function _processStore($storeId, $mailchimpStoreId) { - $this->_helper->log(__METHOD__); $batchArray = array(); $results = array(); if ($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_ECOMMERCE_ACTIVE,$storeId)) { diff --git a/Helper/Data.php b/Helper/Data.php index 057d2860..ed42b187 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -554,6 +554,7 @@ public function resetEcommerce() } public function saveEcommerceData($storeId, $entityId , $date, $error, $modified, $type, $deleted = 0, $token = null) { + $chimpSyncEcommerce = $this->getChimpSyncEcommerce($storeId,$entityId,$type); $chimpSyncEcommerce->setMailchimpStoreId($storeId); $chimpSyncEcommerce->setType($type); @@ -591,7 +592,6 @@ public function loadStores() if($store['platform']!=self::PLATFORM) { continue; } - $this->log($store); $mstore = $this->_mailChimpStoresFactory->create(); $mstore->setApikey(trim($apiKey)); $mstore->setStoreid($store['id']); diff --git a/Model/Api/Cart.php b/Model/Api/Cart.php index c7938ad3..a45330ed 100644 --- a/Model/Api/Cart.php +++ b/Model/Api/Cart.php @@ -104,7 +104,6 @@ public function __construct( */ public function createBatchJson($magentoStoreId) { - $this->_helper->log(__METHOD__); $allCarts = array(); if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_ABANDONEDCART_ACTIVE,$magentoStoreId)) { return $allCarts; @@ -135,7 +134,6 @@ public function createBatchJson($magentoStoreId) */ protected function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) { - $this->_helper->log(__METHOD__); $allCarts = array(); $convertedCarts = $this->_getQuoteCollection(); // get only the converted quotes @@ -152,7 +150,6 @@ protected function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) $convertedCarts->getSelect()->where("m4m.mailchimp_sync_deleted = 0"); // limit the collection $convertedCarts->getSelect()->limit(self::BATCH_LIMIT); - $this->_helper->log((string)$convertedCarts->getSelect()); /** * @var $cart \Magento\Quote\Model\Quote */ @@ -194,7 +191,6 @@ protected function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) */ protected function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) { - $this->_helper->log(__METHOD__); $allCarts = array(); $modifiedCarts = $this->_getQuoteCollection(); // select carts with no orders @@ -213,7 +209,6 @@ protected function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) " AND m4m.mailchimp_sync_delta < main_table.updated_at"); // limit the collection $modifiedCarts->getSelect()->limit(self::BATCH_LIMIT); - $this->_helper->log((string)$modifiedCarts->getSelect()); /** * @var $cart \Magento\Quote\Model\Quote */ @@ -288,7 +283,6 @@ protected function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) */ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId) { - $this->_helper->log(__METHOD__); $allCarts = array(); $newCarts = $this->_getQuoteCollection(); $newCarts->addFieldToFilter('is_active', array('eq'=>1)); @@ -311,32 +305,24 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $newCarts->getSelect()->where("m4m.mailchimp_sync_delta IS NULL"); // limit the collection $newCarts->getSelect()->limit(self::BATCH_LIMIT); - $this->_helper->log((string)$newCarts->getSelect()); /** * @var $cart \Magento\Quote\Model\Quote */ foreach ($newCarts as $cart) { - $this->_helper->log('each cart'); $cartId = $cart->getEntityId(); $orderCollection = $this->_getOrderCollection(); $orderCollection->addFieldToFilter('main_table.customer_email', array('eq' => $cart->getCustomerEmail())) ->addFieldToFilter('main_table.updated_at', array('from' => $cart->getUpdatedAt())); //if cart is empty or customer has an order made after the abandonment skip current cart. - $this->_helper->log((string)$orderCollection->getSelect()); if (!count($cart->getAllVisibleItems()) || $orderCollection->getSize()) { - $this->_helper->log("cart is empty, leave"); $this->_updateQuote($mailchimpStoreId, $cartId, $this->_date->gmtDate()); continue; } - $this->_helper->log('before get the customer by email'); $customer = $this->_customerFactory->create(); $customer->setWebsiteId($magentoStoreId); $customer->loadByEmail($cart->getCustomerEmail()); - $this->_helper->log('after get customer by email'); if ($customer->getEmail() != $cart->getCustomerEmail()) { - $this->_helper->log('not same email'); - $this->_helper->log('before get all carts'); $allCartsForEmail = $this->_getAllCartsByEmail($cart->getCustomerEmail(), $mailchimpStoreId, $magentoStoreId); foreach ($allCartsForEmail as $cartForEmail) { $alreadySentCartId = $cartForEmail->getEntityId(); @@ -358,7 +344,6 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId) } // send the products that not already sent - $this->_helper->log('before send modified products'); $productData = $this->_apiProduct->sendQuoteModifiedProduct($cart, $mailchimpStoreId, $magentoStoreId); if (count($productData)) { foreach($productData as $p) { @@ -366,7 +351,6 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $this->_counter += 1; } } - $this->_helper->log('after send modified products'); $cartJson = $this->_makeCart($cart, $mailchimpStoreId, $magentoStoreId); if ($cartJson!="") { @@ -392,7 +376,6 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId) */ protected function _getAllCartsByEmail($email, $mailchimpStoreId, $magentoStoreId) { - $this->_helper->log(__METHOD__); $allCartsForEmail = $this->_getQuoteCollection(); $allCartsForEmail->addFieldToFilter('is_active', array('eq' => 1)); $allCartsForEmail->addFieldToFilter('store_id', array('eq' => $magentoStoreId)); @@ -405,7 +388,6 @@ protected function _getAllCartsByEmail($email, $mailchimpStoreId, $magentoStoreI ); // be sure that the quotes are already in mailchimp and not deleted $allCartsForEmail->getSelect()->where("m4m.mailchimp_sync_deleted = 0"); - $this->_helper->log((string)$allCartsForEmail->getSelect()); return $allCartsForEmail; } @@ -417,17 +399,14 @@ protected function _getAllCartsByEmail($email, $mailchimpStoreId, $magentoStoreI */ protected function _makeCart(\Magento\Quote\Model\Quote $cart, $mailchimpStoreId, $magentoStoreId) { - $this->_helper->log(__METHOD__); $this->_token = null; $campaignId = $cart->getMailchimpCampaignId(); $oneCart = array(); $oneCart['id'] = $cart->getEntityId(); - $this->_helper->log('before get customer'); $oneCart['customer'] = $this->_getCustomer($cart, $mailchimpStoreId, $magentoStoreId); if ($campaignId) { $oneCart['campaign_id'] = $campaignId; } - $this->_helper->log('after get customer'); $oneCart['checkout_url'] = $this->_getCheckoutUrl($cart); $oneCart['currency_code'] = $cart->getQuoteCurrencyCode(); @@ -618,7 +597,6 @@ protected function _getOrderCollection() */ protected function _updateQuote($storeId, $entityId, $sync_delta, $sync_error='', $sync_modified=0, $sync_deleted=0) { - $this->_helper->log(__METHOD__); $this->_helper->saveEcommerceData($storeId, $entityId, $sync_delta, $sync_error, $sync_modified, \Ebizmarts\MailChimp\Helper\Data::IS_QUOTE, $sync_deleted, $this->_token); } diff --git a/Model/Api/Customer.php b/Model/Api/Customer.php index 95fe37ac..2f9359ea 100644 --- a/Model/Api/Customer.php +++ b/Model/Api/Customer.php @@ -94,13 +94,11 @@ public function sendCustomers($storeId) "OR (m4m.mailchimp_sync_delta > '".$this->_helper->getMCMinSyncDateFlag(). "' and m4m.mailchimp_sync_modified = 1)"); $collection->getSelect()->limit(self::MAX); - $this->_helper->log((string)$collection->getSelect()); $counter = 0; $customerArray = array(); foreach($collection as $item) { - $this->_helper->log('process each customer'); $customer = $this->_customerFactory->create(); $customer->getResource()->load($customer,$item->getId()); @@ -135,7 +133,6 @@ public function sendCustomers($storeId) */ protected function _buildCustomerData(\Magento\Customer\Model\Customer $customer) { - $this->_helper->log(__METHOD__); $point = 0; $data = array(); $data["id"] = $customer->getId(); @@ -149,7 +146,6 @@ protected function _buildCustomerData(\Magento\Customer\Model\Customer $customer array('neq',\Magento\Sales\Model\Order::STATE_CANCELED), array('neq',\Magento\Sales\Model\Order::STATE_CLOSED))) ->addAttributeToFilter('customer_id', array('eq' => $customer->getId())); - $this->_helper->log((string)$orderCollection->getSelect()); $totalOrders = 0; $totalAmountSpent = 0; /** @@ -163,7 +159,6 @@ protected function _buildCustomerData(\Magento\Customer\Model\Customer $customer $data['orders_count'] = $totalOrders; $data['total_spent'] = $totalAmountSpent; $address = $customer->getDefaultBillingAddress(); - $this->_helper->log('after get billing address'); if($address) { $customerAddress = array(); if ($street = $address->getStreet()) { @@ -175,30 +170,24 @@ protected function _buildCustomerData(\Magento\Customer\Model\Customer $customer $customerAddress["address2"] = $street[1]; } } - $this->_helper->log('after street'); if ($address->getCity()) { $customerAddress["city"] = $address->getCity(); } - $this->_helper->log('after city'); if ($address->getRegion()) { $customerAddress["province"] = $address->getRegion(); } - $this->_helper->log('after region'); if ($address->getRegionCode()) { $customerAddress["province_code"] = $address->getRegionCode(); } - $this->_helper->log('after region code'); if ($address->getPostcode()) { $customerAddress["postal_code"] = $address->getPostcode(); } - $this->_helper->log('after post code'); if ($address->getCountry()) { $country = $this->_countryInformation->getCountryInfo($address->getCountryId()); $countryName = $country->getFullNameLocale(); $customerAddress["country"] = $countryName; $customerAddress["country_code"] = $country->getTwoLetterAbbreviation(); } - $this->_helper->log('after country'); if (count($customerAddress)) { $data["address"] = $customerAddress; } @@ -210,7 +199,6 @@ protected function _buildCustomerData(\Magento\Customer\Model\Customer $customer // } // } } - $this->_helper->log('before return'); return $data; } diff --git a/Model/Api/Order.php b/Model/Api/Order.php index f5ca3182..1983a34c 100644 --- a/Model/Api/Order.php +++ b/Model/Api/Order.php @@ -128,7 +128,6 @@ public function __construct( */ public function sendOrders($magentoStoreId) { - $this->_helper->log(__METHOD__); $batchArray = array(); // get all the orders modified @@ -144,7 +143,6 @@ protected function _getCollection() } protected function _getModifiedOrders($magentoStoreId) { - $this->_helper->log(__METHOD__); $batchArray = array(); $mailchimpStoreId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,$magentoStoreId); $modifiedOrders = $this->_getCollection(); @@ -161,12 +159,10 @@ protected function _getModifiedOrders($magentoStoreId) $modifiedOrders->getSelect()->where("m4m.mailchimp_sync_modified = 1 AND m4m.mailchimp_store_id = '".$mailchimpStoreId."'"); // limit the collection $modifiedOrders->getSelect()->limit(self::BATCH_LIMIT); - $this->_helper->log((string)$modifiedOrders->getSelect()); /** * @var $order \Magento\Sales\Model\Order */ foreach ($modifiedOrders as $item) { - $this->_helper->log('inside the foreach'); try { $error = ''; $orderId = $item->getEntityId(); @@ -205,7 +201,6 @@ protected function _getModifiedOrders($magentoStoreId) protected function _getNewOrders($magentoStoreId) { - $this->_helper->log(__METHOD__); $batchArray = array(); $mailchimpStoreId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,$magentoStoreId); $newOrders = $this->_getCollection(); @@ -225,20 +220,15 @@ protected function _getNewOrders($magentoStoreId) $newOrders->getSelect()->where("m4m.mailchimp_sync_delta IS NULL"); // limit the collection $newOrders->getSelect()->limit(self::BATCH_LIMIT); - $this->_helper->log((string)$newOrders->getSelect()); /** * @var $order \Magento\Sales\Model\Order */ foreach ($newOrders as $item) { - $this->_helper->log('inside foreach'); try { $error = ''; - $this->_helper->log('before get id'); $orderId = $item->getEntityId(); - $this->_helper->log('before get the order'); - $order = $this->_order->get($orderId);; + $order = $this->_order->get($orderId); //create missing products first - $this->_helper->log('before send products'); $productData = $this->_apiProduct->sendModifiedProduct($order, $mailchimpStoreId); if (count($productData)) { foreach ($productData as $p) { @@ -246,7 +236,6 @@ protected function _getNewOrders($magentoStoreId) $this->_counter++; } } - $this->_helper->log('before generate order post'); $orderJson = $this->GeneratePOSTPayload($order, $mailchimpStoreId, $magentoStoreId); if (!empty($orderJson)) { $batchArray[$this->_counter]['method'] = "POST"; @@ -280,7 +269,6 @@ protected function _getNewOrders($magentoStoreId) */ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailchimpStoreId, $magentoStoreId, $isModifiedOrder = false) { - $this->_helper->log(__METHOD__); $data = array(); $data['id'] = $order->getEntityId(); if ($order->getMailchimpCampaignId()) { @@ -290,14 +278,12 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc if ($order->getMailchimpLandingPage()) { $data['landing_site'] = $order->getMailchimpLandingPage(); } - $this->_helper->log('before charge currency'); $data['currency_code'] = $order->getOrderCurrencyCode(); $data['order_total'] = $order->getGrandTotal(); $data['tax_total'] = $order->getTaxAmount(); $data['discount_total'] = abs($order->getDiscountAmount()); $data['shipping_total'] = $order->getShippingAmount(); $statusArray = $this->_getMailChimpStatus($order); - $this->_helper->log('before charge status'); if (isset($statusArray['financial_status'])) { $data['financial_status'] = $statusArray['financial_status']; } @@ -329,7 +315,6 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc //order lines $items = $order->getAllVisibleItems(); - $this->_helper->log('before processing items'); $itemCount = 0; /** * @var $item \Magento\Sales\Model\Order\Item @@ -365,7 +350,6 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc } //customer data - $this->_helper->log('before get the customer'); $api = $this->_helper->getApi(); $customers = array(); @@ -374,7 +358,6 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc } catch (\Mailchimp_Error $e) { $this->_helper->log($e->getMessage()); } - $this->_helper->log('after get the customer'); if (!$isModifiedOrder) { if (isset($customers['total_items']) && $customers['total_items'] > 0) { @@ -416,7 +399,6 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc } } // $store = Mage::getModel('core/store')->load($magentoStoreId); - $this->_helper->log('before charge customer data'); $data['order_url'] = $this->_urlHelper->getUrl( 'sales/order/view/', array( @@ -528,7 +510,6 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc // } } //customer orders data - $this->_helper->log('before charge totals'); $orderCollection = $this->_orderCollectionFactory->create(); $orderCollection->addFieldToFilter('state', array( @@ -564,7 +545,6 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc protected function _getMailChimpStatus(\Magento\Sales\Model\Order $order) { - $this->_helper->log(__METHOD__); $mailChimpFinancialStatus = null; $mailChimpFulfillmentStatus = null; $totalItemsOrdered = $order->getData('total_qty_ordered'); @@ -656,7 +636,6 @@ protected function _getMailChimpStatus(\Magento\Sales\Model\Order $order) protected function _updateOrder($storeId, $entityId, $sync_delta, $sync_error, $sync_modified) { - $this->_helper->log(__METHOD__); $this->_helper->saveEcommerceData($storeId, $entityId, $sync_delta, $sync_error, $sync_modified, \Ebizmarts\MailChimp\Helper\Data::IS_ORDER); } diff --git a/Model/Api/Product.php b/Model/Api/Product.php index 4f2116d9..227e1327 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -103,7 +103,6 @@ public function _sendProducts($storeId) $collection->getSelect()->where("m4m.mailchimp_sync_delta IS null OR (m4m.mailchimp_sync_delta > '".$this->_helper->getMCMinSyncDateFlag(). "' and m4m.mailchimp_sync_modified = 1)"); $collection->getSelect()->limit(self::MAX); - $this->_helper->log((string)$collection->getSelect()); foreach($collection as $item) { /** @@ -289,31 +288,26 @@ protected function _buildProductData(\Magento\Catalog\Model\Product $product, $ */ public function sendModifiedProduct(\Magento\Sales\Model\Order $order,$mailchimpStoreId) { - $this->_helper->log(__METHOD__); $data = array(); $batchId = \Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT . '_' . $this->_date->gmtTimestamp(); $items = $order->getAllVisibleItems(); foreach ($items as $item) { - $this->_helper->log($item->getProductId()); //@todo get from the store not the default $product = $this->_productRepository->getById($item->getProductId()); $productSyncData = $this->_chimpSyncEcommerce->getByStoreIdType($mailchimpStoreId,$product->getId(), \Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT); if ($product->getId()!=$item->getProductId()||$product->getTypeId()=='bundle'||$product->getTypeId()=='grouped') { - $this->_helper->log('continue is bundle/grouped'); continue; } if ($productSyncData->getMailchimpSyncModified() && $productSyncData->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) { - $this->_helper->log('is an old product'); $data[] = $this->_buildOldProductRequest($product,$batchId); $this->_updateProduct($mailchimpStoreId, $product->getId(), $this->_date->gmtDate(),'',0); } elseif (!$productSyncData->getMailchimpSyncDelta() || $productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) { - $this->_helper->log('is a new product'); $data[] = $this->_buildNewProductRequest($product, $mailchimpStoreId); $this->_updateProduct($mailchimpStoreId, $product->getId(), $this->_date->gmtDate(),'',0); } @@ -323,7 +317,6 @@ public function sendModifiedProduct(\Magento\Sales\Model\Order $order,$mailchimp public function sendQuoteModifiedProduct(\Magento\Quote\Model\Quote $quote,$mailchimpStoreId) { - $this->_helper->log(__METHOD__); $data = array(); $batchId = \Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT . '_' . $this->_date->gmtTimestamp(); $items = $quote->getAllVisibleItems(); @@ -332,25 +325,21 @@ public function sendQuoteModifiedProduct(\Magento\Quote\Model\Quote $quote,$mail */ foreach ($items as $item) { - $this->_helper->log($item->getProductId()); //@todo get from the store not the default $product = $this->_productRepository->getById($item->getProductId()); $productSyncData = $this->_chimpSyncEcommerce->getByStoreIdType($mailchimpStoreId,$product->getId(), \Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT); if ($product->getId()!=$item->getProductId()||$product->getTypeId()=='bundle'||$product->getTypeId()=='grouped') { - $this->_helper->log('continue is bundle/grouped'); continue; } if ($productSyncData->getMailchimpSyncModified() && $productSyncData->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) { - $this->_helper->log('is an old product'); $data[] = $this->_buildOldProductRequest($product,$batchId); $this->_updateProduct($mailchimpStoreId, $product->getId(), $this->_date->gmtDate(),'',0); } elseif (!$productSyncData->getMailchimpSyncDelta() || $productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) { - $this->_helper->log('is a new product'); $data[] = $this->_buildNewProductRequest($product, $mailchimpStoreId); $this->_updateProduct($mailchimpStoreId, $product->getId(), $this->_date->gmtDate(),'',0); } diff --git a/Model/Api/Result.php b/Model/Api/Result.php index 7f3e813d..d228313d 100644 --- a/Model/Api/Result.php +++ b/Model/Api/Result.php @@ -64,7 +64,7 @@ public function processResponses($storeId, $isMailChimpStoreId = false, $mailchi $item = null; foreach ($collection as $item) { try { - $storeId = ($isMailChimpStoreId) ? 0 : $storeId; +// $storeId = ($isMailChimpStoreId) ? 0 : $storeId; $files = $this->getBatchResponse($item->getBatchId(), $storeId); if (count($files)) { $this->processEachResponseFile($files, $item->getBatchId(), $mailchimpStoreId, $storeId); @@ -130,13 +130,13 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId , $line = explode('_', $item->operation_id); $type = $line[0]; $id = $line[2]; + $this->_helper->log("type [$type] id [$id] store[$storeId]"); $mailchimpErrors = $this->_chimpErrors->create(); //parse error $response = json_decode($item->response); $this->_helper->log($response); - $this->_helper->log("type [$type] id [$id]"); $errorDetails = ""; if (!empty($response->errors)) { foreach ($response->errors as $error) { @@ -154,7 +154,8 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId , /** * @var \Ebizmarts\MailChimp\Model\MailChimpSyncEcommerce $chimpSync */ - $chimpSync = $this->_helper->getChimpSyncEcommerce($storeId,$id,$type); + $chimpSync = $this->_helper->getChimpSyncEcommerce($mailchimpStoreId,$id,$type); + $this->_helper->log($chimpSync); $chimpSync->setData("mailchimp_sync_error", $error); $chimpSync->getResource()->save($chimpSync); $mailchimpErrors->setType($response->type);