Skip to content

Commit

Permalink
remove logs
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed May 2, 2017
1 parent 3ed042b commit e95e12b
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 73 deletions.
2 changes: 0 additions & 2 deletions Cron/Ecommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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']);
Expand Down
22 changes: 0 additions & 22 deletions Model/Api/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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));
Expand All @@ -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();
Expand All @@ -358,15 +344,13 @@ 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) {
$allCarts[$this->_counter] = $p;
$this->_counter += 1;
}
}
$this->_helper->log('after send modified products');

$cartJson = $this->_makeCart($cart, $mailchimpStoreId, $magentoStoreId);
if ($cartJson!="") {
Expand All @@ -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));
Expand All @@ -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;
}

Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 0 additions & 12 deletions Model/Api/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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();
Expand All @@ -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;
/**
Expand All @@ -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()) {
Expand All @@ -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;
}
Expand All @@ -210,7 +199,6 @@ protected function _buildCustomerData(\Magento\Customer\Model\Customer $customer
// }
// }
}
$this->_helper->log('before return');
return $data;
}

Expand Down
23 changes: 1 addition & 22 deletions Model/Api/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public function __construct(
*/
public function sendOrders($magentoStoreId)
{
$this->_helper->log(__METHOD__);
$batchArray = array();

// get all the orders modified
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -225,28 +220,22 @@ 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) {
$batchArray[$this->_counter] = $p;
$this->_counter++;
}
}
$this->_helper->log('before generate order post');
$orderJson = $this->GeneratePOSTPayload($order, $mailchimpStoreId, $magentoStoreId);
if (!empty($orderJson)) {
$batchArray[$this->_counter]['method'] = "POST";
Expand Down Expand Up @@ -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()) {
Expand All @@ -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'];
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit e95e12b

Please sign in to comment.