Skip to content

Commit

Permalink
Merge pull request #5 from sendsmaily/develop/readme-and-standards-up…
Browse files Browse the repository at this point in the history
…date

Improved coding standards and changed readme file about abandoned cart.
  • Loading branch information
sinukaarel authored Jan 8, 2019
2 parents 693a8e1 + 477bdf1 commit 7a677de
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Automatically subscribe newsletter subscribers to a Smaily subscribers list, gen
- Collect new user data for subscribed users
- Generate data log for each update

### Abandoned cart

- Get customer abandoned cart info and send recovery e-mails with Smaily templates.
- Set prefered delay time when cart is considered abandoned.

## Requirements

Smaily for Prestashop requires PHP 5.6+ (PHP 7.0+ recommended). You'll also need to be running Prestashop 1.7+.
Expand Down Expand Up @@ -63,8 +68,35 @@ All development for Smaily for Prestashop is [handled via GitHub](https://github

Cron update data-log is stored in the root folder of Smaily plugin, inside "smaily-cron.txt" file.

### How can I access additional Abandoned cart parameters in Smaily template editor?

Here is a list of all the parameters available in Smaily email templating engine:

Customer first name: {{ firstname }}.

Customer last name: {{ lastname }}

Store url: {{ store_url }}.

Up to 10 products can be received in Smaily templating engine. You can refrence each product with number 1-10 behind parameter name.

Product name: {{ product_name_[1-10] }}.

Product description: {{ product_description_short_[1-10] }}.

Product quantity: {{ product_quantity_[1-10] }}.

Product price: {{ product_price_[1-10] }}.

Product category: {{ product_category_[1-10] }}.

## Changelog

### 1.0 - 2018
### 1.1.0 - 2019

- New Feature. Added Abandoned cart support.
- Changed admin page behaviour when API credentials allready validated.

### 1.0.0 - 2018

- This is the first public release.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function ajaxProcessSmailyValidate()
* @param string $method GET or POST method
* @return array $result Response from Smaily
*/
public function callApi($endpoint, $subdomain, $username, $password, $data = [], $method = 'GET')
public function callApi($endpoint, $subdomain, $username, $password, $data = array(), $method = 'GET')
{

$apiUrl = "https://" . $subdomain . ".sendsmaily.net/api/" . trim($endpoint, '/') . ".php";
Expand Down
17 changes: 8 additions & 9 deletions controllers/front/SmailyCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function init()
} else {
die($this->l('Access denied! '));
}

}

/**
Expand Down Expand Up @@ -110,8 +109,8 @@ private function abandonedCart()
{
if (Configuration::get('SMAILY_ENABLE_ABANDONED_CART') === "1") {
// Settings
$autoresponder = stripslashes(pSQL((Configuration::get('SMAILY_CART_AUTORESPONDER'))));
$autoresponder = unserialize($autoresponder);
$autoresponder = unserialize(Configuration::get('SMAILY_CART_AUTORESPONDER'));
$autoresponder_id = pSQL($autoresponder['id']);
$delay = pSQL(Configuration::get('SMAILY_ABANDONED_CART_TIME'));
// Values to sync array
$sync_fields = unserialize(Configuration::get('SMAILY_CART_SYNCRONIZE_ADDITIONAL'));
Expand Down Expand Up @@ -150,11 +149,11 @@ private function abandonedCart()
$cart = new Cart($abandoned_cart['id_cart']);
$products = $cart->getProducts();

$adresses = [
$adresses = array(
'email' => $abandoned_cart['email'],
'firstname' => $abandoned_cart['firstname'],
'lastname' => $abandoned_cart['lastname'],
];
);

// Collect products of abandoned cart.
if (!empty($products)) {
Expand All @@ -170,10 +169,10 @@ private function abandonedCart()
// Add shop url.
$adresses['store_url'] = _PS_BASE_URL_.__PS_BASE_URI__;
// Smaily api query.
$query = [
'autoresponder' => $autoresponder['id'],
'addresses' => [$adresses]
];
$query = array(
'autoresponder' => $autoresponder_id,
'addresses' => array($adresses)
);
// Send cart data to smaily api.
$response = $this->callApi('autoresponder', $query, 'POST');
// If email sent successfully update sent status in database.
Expand Down
18 changes: 11 additions & 7 deletions smailyforprestashop.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function install()
`id_customer` INT UNSIGNED NULL ,
`id_cart` INT UNSIGNED NULL ,
`date_sent` DATETIME NOT NULL) ENGINE='._MYSQL_ENGINE_;
if (!$result = Db::getInstance()->execute($sql)) {
if (!Db::getInstance()->execute($sql)) {
return false;
}
return true;
Expand Down Expand Up @@ -216,7 +216,7 @@ public function getContent()
$enable_abandoned_cart = pSQL(Tools::getValue('SMAILY_ENABLE_ABANDONED_CART'));
// Abandoned cart delay time
$abandoned_cart_time = pSQL(Tools::getValue('SMAILY_ABANDONED_CART_TIME'));
$abandoned_cart_time = trim(Tools::stripslashes($abandoned_cart_time));
$abandoned_cart_time = (int) trim(Tools::stripslashes($abandoned_cart_time));
// Abandoned cart Autoresponder
$cart_autoresponder = pSQL((Tools::getValue('SMAILY_CART_AUTORESPONDER')));
$cart_autoresponder = str_replace('\"', '"', $cart_autoresponder);
Expand All @@ -237,15 +237,17 @@ public function getContent()
$cart_escaped_sync_additional[] = pSQL($value);
}
}
if (!Validate::isInt($abandoned_cart_time) ||
intval($abandoned_cart_time) < 1) {
if ($abandoned_cart_time < 1) {
// Display error message.
$output .= $this->displayError($this->l('Abandoned cart delay has to be number value over 0.'));
} else {
Configuration::updateValue('SMAILY_ENABLE_ABANDONED_CART', $enable_abandoned_cart);
Configuration::updateValue('SMAILY_CART_AUTORESPONDER', serialize($escaped_cart_autoresponder));
Configuration::updateValue('SMAILY_ABANDONED_CART_TIME', $abandoned_cart_time);
Configuration::updateValue('SMAILY_CART_SYNCRONIZE_ADDITIONAL', serialize($cart_escaped_sync_additional));
Configuration::updateValue(
'SMAILY_CART_SYNCRONIZE_ADDITIONAL',
serialize($cart_escaped_sync_additional)
);
// Display success message.
$output .= $this->displayConfirmation($this->l('Abandoned cart settings updated'));
}
Expand All @@ -264,10 +266,12 @@ public function getContent()
$cart_sync_array = array();
}
// Get autoresponder values for template.
$autoresponder_for_template = stripslashes(pSQL((Configuration::get('SMAILY_AUTORESPONDER'))));
$autoresponder_for_template = pSQL((Configuration::get('SMAILY_AUTORESPONDER')));
$autoresponder_for_template = str_replace('\"', '"', $autoresponder_for_template);
$autoresponder_for_template = unserialize($autoresponder_for_template);
// Get abandoned cart autoresponder values for template.
$cart_autoresponder_for_template = stripslashes(pSQL((Configuration::get('SMAILY_CART_AUTORESPONDER'))));
$cart_autoresponder_for_template = pSQL((Configuration::get('SMAILY_CART_AUTORESPONDER')));
$cart_autoresponder_for_template = str_replace('\"', '"', $cart_autoresponder_for_template);
$cart_autoresponder_for_template = unserialize($cart_autoresponder_for_template);
// Assign variables to template if available.
$this->context->smarty->assign(array(
Expand Down
1 change: 1 addition & 0 deletions translations/et.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_ad3d06d03d94223fa652babc913de686'] = 'Kontrolli';
$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_872bc575218e7dd2c749633da28c24ab'] = 'Automaatvastaja';
$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_3c6afc2203f77fb15d7b584e12960540'] = 'Vali Automaatvastaja';
$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_99770d280600b3c7ecc14faec49165ed'] = '(valitud)';
$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_c453535704cee5f76534f9feee2ad0d0'] = 'Lisa väljad sünkroniseerimiseks';
$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_04176f095283bc729f1e3926967e7034'] = 'Eesnimi';
$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_dff4bf10409100d989495c6d5486035e'] = 'Perekonnanimi';
Expand Down
4 changes: 2 additions & 2 deletions views/templates/admin/smaily_configure.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
</option>
{else}
<option value='{$smaily_autoresponder|json_encode}'>
{$smaily_autoresponder['name']} {l s="(selected)" m='smailyforprestashop'}
{$smaily_autoresponder['name']} {l s="(selected)" mod='smailyforprestashop'}
</option>
{/if}
</select>
Expand Down Expand Up @@ -232,7 +232,7 @@
</option>
{else}
<option value='{$smaily_cart_autoresponder|json_encode}'>
{$smaily_cart_autoresponder['name']} {l s="(selected)" m='smailyforprestashop'}
{$smaily_cart_autoresponder['name']} {l s="(selected)" mod='smailyforprestashop'}
</option>
{/if}
</select>
Expand Down

0 comments on commit 7a677de

Please sign in to comment.