Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to 1.1.5 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All rights belong to EbizMarts and the only changes we are making are:

## Version

1.1.0 as of 2013-02-25
1.1.5 as of 2013-03-20

Please always check http://ebizmarts.com for the latest version and do let us
know if we fall behind.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$this->setCollection($collection);
$collection->getSelect()->join('sales_flat_quote' , 'main_table.increment_id = sales_flat_quote.reserved_order_id', 'ebizmarts_abandonedcart_flag');
$collection->addFieldToFilter('sales_flat_quote.ebizmarts_abandonedcart_flag',array('eq' => 1));
$sales_flat_order_table = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
$collection->getSelect()->join($sales_flat_order_table , 'main_table.increment_id = '.$sales_flat_order_table.'.increment_id', 'ebizmarts_abandonedcart_flag');
$collection->addFieldToFilter($sales_flat_order_table.'.ebizmarts_abandonedcart_flag',array('eq' => 1));
return parent::_prepareCollection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ protected function _prepareLayout()

$collection = Mage::getResourceModel('ebizmarts_abandonedcart/order_collection')
->calculateSales($isFilter);
$collection->getSelect()->join('sales_flat_quote' , 'main_table.increment_id = sales_flat_quote.reserved_order_id', 'ebizmarts_abandonedcart_flag');
$collection->addFieldToFilter('sales_flat_quote.ebizmarts_abandonedcart_flag',array('eq' => 1));

// $collection->getSelect()->join('sales_flat_quote' , 'main_table.increment_id = sales_flat_quote.reserved_order_id', 'ebizmarts_abandonedcart_flag');
$collection->addFieldToFilter('main_table.ebizmarts_abandonedcart_flag',array('eq' => 1));


if ($this->getRequest()->getParam('store')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ protected function _prepareLayout()
$collection = Mage::getResourceModel('ebizmarts_abandonedcart/order_collection')
->addCreateAtPeriodFilter($period)
->calculateTotals($isFilter);
$collection->getSelect()->join('sales_flat_quote' , 'main_table.increment_id = sales_flat_quote.reserved_order_id', 'ebizmarts_abandonedcart_flag');
$collection->addFieldToFilter('sales_flat_quote.ebizmarts_abandonedcart_flag',array('eq' => 1));
// $collection->getSelect()->join('sales_flat_quote' , 'main_table.increment_id = sales_flat_quote.reserved_order_id', 'ebizmarts_abandonedcart_flag');
$collection->addFieldToFilter('main_table.ebizmarts_abandonedcart_flag',array('eq' => 1));



Expand Down Expand Up @@ -111,14 +111,44 @@ protected function _prepareLayout()
}
// add totals for emails
if($particular) {
$aux = $particular['sent'] - $particular['hard_bounces']; // - $particular['soft_bounces'];
$received = sprintf('%d (%2.2f%%)',$aux,$aux/$particular['sent']*100);
$this->addTotal($this->__('Emails Sent'),$particular['sent'],true);
$this->addTotal($this->__('Emails Received'),$received,true);
$opens = sprintf('%d (%2.2f%%)',$particular['unique_opens'],$particular['unique_opens']/$particular['sent']*100);

$_sent = $particular['sent'];
$_hard_bounces = $particular['hard_bounces'];
$_unique_opens = $particular['unique_opens'];
$_unique_clicks = $particular['unique_clicks'];


//Emails Sent and Received
$aux = $_sent - $_hard_bounces; // - $particular['soft_bounces'];
if($aux > 0) {
$aux2 = $aux/ $_sent*100;
}else{
$aux2 = 0;
}
$received = sprintf('%d (%2.2f%%)', $aux, $aux2);

$this->addTotal($this->__('Emails Sent'), $_sent,true);
$this->addTotal($this->__('Emails Received'), $received,true);

//Emails Opened
if($_unique_opens > 0) {
$emailsOpened = $_unique_opens / $_sent*100;
}else{
$emailsOpened = 0;
}

$opens = sprintf('%d (%2.2f%%)', $_unique_opens, $emailsOpened);
$this->addTotal($this->__('Emails Opened'),$opens,true);
$clicks = sprintf('%d (%2.2f%%)',$particular['unique_clicks'],$particular['unique_clicks']/$particular['unique_opens']*100);
$this->addTotal($this->__('Emails Clicked'),$clicks,true);

//Emails Clicked
if($_unique_clicks > 0){
$emailsClicked = $_unique_clicks / $_unique_opens*100;
}else{
$emailsClicked = 0;
}

$clicks = sprintf('%d (%2.2f%%)', $_unique_clicks, $emailsClicked);
$this->addTotal($this->__('Emails Clicked'), $clicks,true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Created by Ebizmarts
* User: [email protected]
* Date: 3/11/13
* Time: 3:03 PM
*/
class Ebizmarts_AbandonedCart_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field
{
public function render(Varien_Data_Form_Element_Abstract $element)
{
$element->setFormat(Varien_Date::DATE_INTERNAL_FORMAT);
$element->setImage($this->getSkinUrl('images/grid-cal.gif'));
return parent::render($element);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class Ebizmarts_AbandonedCart_Block_Email_Order_Items extends Mage_Sales_Block_Items_Abstract
{
public function _construct()
{
$this->setTemplate('ebizmarts_abandonedcart/email_order_items.phtml');
}
}
26 changes: 26 additions & 0 deletions app/code/community/Ebizmarts/AbandonedCart/Model/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Created by Ebizmarts
* User: [email protected]
* Date: 3/20/13
* Time: 8:34 AM
*/
class Ebizmarts_AbandonedCart_Model_Config
{
const ACTIVE = "ebizmarts_abandonedcart/general/active";
const EMAIL_TEMPLATE_XML_PATH = 'ebizmarts_abandonedcart/general/template';
const EMAIL_TEMPLATE_XML_PATH_W_COUPON = 'ebizmarts_abandonedcart/general/coupon_template';
const DAYS = "ebizmarts_abandonedcart/general/days";
const SENDER = "ebizmarts_abandonedcart/general/identity";
const MAXTIMES = "ebizmarts_abandonedcart/general/max";
const COUPON_DAYS = "ebizmarts_abandonedcart/coupon/sendon";
const SEND_COUPON = "ebizmarts_abandonedcart/coupon/create";
const FIRST_DATE = "ebizmarts_abandonedcart/general/firstdate";
const COUPON_AMOUNT = "ebizmarts_abandonedcart/coupon/discount";
const COUPON_AUTOMATIC = "ebizmarts_abandonedcart/coupon/automatic";
const COUPON_CODE = "ebizmarts_abandonedcart/coupon/couponcode";
const COUPON_EXPIRE = "ebizmarts_abandonedcart/coupon/expire";
const COUPON_TYPE = "ebizmarts_abandonedcart/coupon/discounttype";
const COUPON_LENGTH = "ebizmarts_abandonedcart/coupon/length";
const COUPON_LABEL = "ebizmarts_abandonedcart/coupon/couponlabel";
}
65 changes: 40 additions & 25 deletions app/code/community/Ebizmarts/AbandonedCart/Model/Cron.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
class Ebizmarts_AbandonedCart_Model_Cron
{
const EMAIL_TEMPLATE_XML_PATH = 'ebizmarts_abandonedcart/general/template';
const EMAIL_TEMPLATE_XML_PATH_W_COUPON = 'ebizmarts_abandonedcart/general/coupon_template';
// const EMAIL_TEMPLATE_XML_PATH = 'ebizmarts_abandonedcart/general/template';
// const EMAIL_TEMPLATE_XML_PATH_W_COUPON = 'ebizmarts_abandonedcart/general/coupon_template';

/**
*
Expand All @@ -12,7 +12,9 @@ public function abandoned()
$allStores = Mage::app()->getStores();
foreach($allStores as $storeid => $val)
{
$this->_proccess($storeid);
if(Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::ACTIVE,$storeid)) {
$this->_proccess($storeid);
}
}
}

Expand All @@ -21,14 +23,14 @@ public function abandoned()
*/
protected function _proccess($store)
{

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$adapter = Mage::getSingleton('core/resource')->getConnection('sales_read');
$days = Mage::getStoreConfig("ebizmarts_abandonedcart/general/days", $store);
$maxtimes = Mage::getStoreConfig("ebizmarts_abandonedcart/general/max", $store);
$sendcoupondays = Mage::getStoreConfig("ebizmarts_abandonedcart/coupon/sendon", $store);
$sendcoupon = Mage::getStoreConfig("ebizmarts_abandonedcart/coupon/create", $store);
$days = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::DAYS, $store);
$maxtimes = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::MAXTIMES, $store);
$sendcoupondays = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::COUPON_DAYS, $store);
$sendcoupon = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::SEND_COUPON, $store);
$firstdate = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::FIRST_DATE, $store);

if(!$days) {
return;
Expand All @@ -38,29 +40,38 @@ protected function _proccess($store)

// get a collection of abandoned carts
$collection = Mage::getResourceModel('reports/quote_collection');
// $collection->prepareForAbandonedReport($store);
$collection->addFieldToFilter('items_count', array('neq' => '0'))
->addFieldToFilter('main_table.is_active', '1')
->addFieldToFilter('main_table.store_id',array('eq'=>$store))
->addSubtotal($store)
->setOrder('updated_at');

$collection->addFieldToFilter('main_table.converted_at', array(array('null'=>true),$this->_getSuggestedZeroDate()))
->addFieldToFilter('main_table.updated_at', array('to' => $from))
->addFieldToFilter('main_table.updated_at', array('to' => $from,'from' => $firstdate))
->addFieldToFilter('main_table.ebizmarts_abandonedcart_counter',array('lt' => $maxtimes));

$collection->addFieldToFilter('main_table.customer_email', array('neq' => ''));
// Mage::log((string)$collection->getSelect());

// for each cart
foreach($collection as $quote)
{
// ckeck if they are any order from the customer with date >=
$collection2 = Mage::getResourceModel('reports/quote_collection');
$collection2->addFieldToFilter('main_table.is_active', '0')
->addFieldToFilter('main_table.reserved_order_id',array('neq' => 'NULL' ))
->addFieldToFilter('main_table.customer_email',array('eq' => $quote->getCustomerEmail()))
->addFieldToFilter('main_table.updated_at',array('from'=>$quote->getUpdatedAt()));
if($collection2->getSize()) {
continue;
}
//
$url = Mage::getBaseUrl('web').'ebizmarts_abandonedcart/abandoned/loadquote?id='.$quote->getEntityId();

$data = array('AbandonedURL'=>$url, 'AbandonedDate' => $quote->getUpdatedAt());
// send email
$mailsubject = 'Abandoned Cart';

$senderid = Mage::getStoreConfig("ebizmarts_abandonedcart/general/identity", $store);
$senderid = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::SENDER, $store);
$sender = array('name'=>Mage::getStoreConfig("trans_email/ident_$senderid/name"), 'email'=> Mage::getStoreConfig("trans_email/ident_$senderid/email"));

$email = $quote->getCustomerEmail();
Expand All @@ -69,20 +80,24 @@ protected function _proccess($store)
$quote2 = Mage::getModel('sales/quote')->loadByIdWithoutStore($quote->getId());
if($sendcoupon && $quote2->getEbizmartsAbandonedcartCounter() + 1 == $sendcoupondays)
{
$templateId = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::EMAIL_TEMPLATE_XML_PATH);
// create a new coupon
list($couponcode,$discount,$toDate) = $this->_createNewCoupon($store,$email);
// $templateId = Mage::getStoreConfig(self::EMAIL_TEMPLATE_XML_PATH_W_COUPON);
$templateId = Mage::getStoreConfig(self::EMAIL_TEMPLATE_XML_PATH);
$vars = array('quote'=>$quote,'url'=>$url, 'couponcode'=>$couponcode,'discount' => $discount, 'todate' => $toDate);
if(Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::COUPON_AUTOMATIC)==2) {
list($couponcode,$discount,$toDate) = $this->_createNewCoupon($store,$email);
$vars = array('quote'=>$quote,'url'=>$url, 'couponcode'=>$couponcode,'discount' => $discount, 'todate' => $toDate, 'name' => $name);
}
else {
$couponcode = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::COUPON_CODE);
$vars = array('quote'=>$quote,'url'=>$url, 'couponcode'=>$couponcode, 'name' => $name);
}
}
else {
$templateId = Mage::getStoreConfig(self::EMAIL_TEMPLATE_XML_PATH);
$templateId = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::EMAIL_TEMPLATE_XML_PATH);
$vars = array('quote'=>$quote,'url'=>$url);

}
$translate = Mage::getSingleton('core/translate');
Mage::log("sending mail to $name $email");
Mage::getModel('core/email_template')->setTemplateSubject($mailsubject)->sendTransactional($templateId,$sender,$email,$name,$vars,$store);
$mail = Mage::getModel('core/email_template')->setTemplateSubject($mailsubject)->sendTransactional($templateId,$sender,$email,$name,$vars,$store);
$translate->setTranslateInLine(true);
$quote2->setEbizmartsAbandonedcartCounter($quote2->getEbizmartsAbandonedcartCounter()+1);
$quote2->save();
Expand All @@ -97,11 +112,11 @@ protected function _proccess($store)
*/
protected function _createNewCoupon($store,$email)
{
$couponamount = Mage::getStoreConfig("ebizmarts_abandonedcart/coupon/discount", $store);
$couponexpiredays = Mage::getStoreConfig("ebizmarts_abandonedcart/coupon/expire", $store);
$coupontype = Mage::getStoreConfig("ebizmarts_abandonedcart/coupon/discounttype", $store);
$couponlength = Mage::getStoreConfig("ebizmarts_abandonedcart/coupon/length", $store);
$couponlabel = Mage::getStoreConfig("ebizmarts_abandonedcart/coupon/couponlabel", $store);
$couponamount = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::COUPON_AMOUNT, $store);
$couponexpiredays = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::COUPON_EXPIRE, $store);
$coupontype = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::COUPON_TYPE, $store);
$couponlength = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::COUPON_LENGTH, $store);
$couponlabel = Mage::getStoreConfig(Ebizmarts_AbandonedCart_Model_Config::COUPON_LABEL, $store);

$fromDate = date("Y-m-d");
$toDate = date('Y-m-d', strtotime($fromDate. " + $couponexpiredays day"));
Expand Down Expand Up @@ -131,7 +146,7 @@ protected function _createNewCoupon($store,$email)
->setStoreLabels(array($couponlabel))
->setSimpleAction($action)
->setDiscountAmount($couponamount)
->setDiscountQty(1)
->setDiscountQty(0)
->setDiscountStep('0')
->setSimpleFreeShipping('0')
->setApplyToShipping('0')
Expand Down
Loading