Skip to content

Commit

Permalink
Merge pull request #19 from sendsmaily/dev/1.4.0
Browse files Browse the repository at this point in the history
1.4.0 release
  • Loading branch information
tomkabel authored Aug 27, 2020
2 parents 5171cd7 + 856a17f commit 2817114
Show file tree
Hide file tree
Showing 12 changed files with 310 additions and 35 deletions.
10 changes: 10 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ RUN if grep -q ${group} /etc/group; then \

# Add local www-data group to the user
RUN usermod -a -G www-data ${username}

WORKDIR /var/www/html

# Modman is used for symlinking plugin files to modules folder
RUN curl -SL https://raw.githubusercontent.com/colinmollenhour/modman/master/modman -o /usr/local/bin/modman \
&& chmod +x /usr/local/bin/modman

ADD ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["apache2-foreground"]
2 changes: 1 addition & 1 deletion .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- DB_NAME=prestashop
volumes:
- prestashop-data:/var/www/html
- ../.:/var/www/html/modules/smailyforprestashop
- ../.:/smailyforprestashop
depends_on:
- db

Expand Down
18 changes: 18 additions & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# Wait for MySQL to start.
mysql_ready() {
mysqladmin ping --host=db --user=db_user --password=db_password
}
while !(mysql_ready); do
sleep 1
echo "Waiting for MySQL to finish start up..."
done

# Link module files to Prestashop.
if [ ! -d ./.modman ]; then
su www-data -s /bin/bash -c "modman init"
fi
su www-data -s /bin/bash -c "modman link /smailyforprestashop"

docker-php-entrypoint "$@"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### 1.4.0

- Added RSS settings tab.
- New options for RSS product feed: order by, order direction, product category.
- Generate RSS feed in more user friendly manner.
- Fix bug which caused invalid CRON URLs, when Friendly URL option was disabled.
- Add Estonian translations for additional fields in abandoned cart settings.

### 1.3.0

- Standardize Abandoned Cart email template parameters across integrations
Expand Down
12 changes: 12 additions & 0 deletions USERGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,15 @@ Registered customers, who have opted for the newsletter will be added to Smaily'
5. There is also an option to **add additional fields** about abandoned carts to send personalized reminder emails.

![Abandoned cart emails](assets/AbandonedCart.png)

## RSS

Smaily's module can create an RSS link of available Prestashop products.
![RSS section](assets/RSS.png)
The module provides several options for generating an RSS feed link.
1. **Products category**: selecting a category will display only products under that category in the RSS feed.
2. **Product limit**: limit what is the maximum amount of products displayed in the RSS feed. Limit can be a value between 1 and 250.
3. **Order by**: sorting order of the products in the RSS feed. Possible options are: date added, date updated, name, price, product ID.
4. **Order direction**: in which direction will the module order products.

The generated RSS feed link can be copied to your template editor's RSS block to display products directly in your newsletter. For this, you can follow our [RSS feed manual](http://help.smaily.com/en/support/solutions/articles/16000077027-rss-feed).
Binary file added assets/RSS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 22 additions & 2 deletions controllers/front/SmailyRssFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,27 @@ public function initContent()

public function generateRssFeed()
{
$products = Product::getProducts($this->context->language->id, 0, 50, 'date_upd', 'desc', false, true);
$limit = (int) Tools::getValue('limit');
$limit = $limit >= 1 && $limit <= 250 ? $limit : 50;

$sort_by = Tools::getValue('sort_by');
$sort_by = in_array($sort_by, SmailyForPrestashop::$allowed_sort_by_values, true) ? $sort_by : 'date_upd';

$sort_order = Tools::getValue('sort_order');
$sort_order = in_array($sort_order, array('asc', 'desc'), true) ? $sort_order : 'desc';

$category_id = (int) Tools::getValue('category_id');
$category_id = $category_id <= 0 ? false : $category_id;

$products = Product::getProducts(
$this->context->language->id,
0, // start number
$limit, // hardcoded 50 in < 1.4.0
$sort_by, // hardcoded date_upd in < 1.4.0
$sort_order, // hardcoded desc in < 1.4.0
$category_id, // hardcoded false in < 1.4.0
true // only active products
);
$baseUrl = Tools::getHttpHost(true).__PS_BASE_URI__;
$rss ='<?xml version="1.0" encoding="utf-8"?>' .
'<rss xmlns:smly="https://sendsmaily.net/schema/editor/rss.xsd" version="2.0">' .
Expand Down Expand Up @@ -75,7 +95,7 @@ public function generateRssFeed()
}
$rss .= '<item>
<title><![CDATA['. $name .']]></title>
<link><![CDATA['. $product_url . ']]></link>
<guid isPermaLink="True">'. $baseUrl . '</guid>
<pubDate>' . date("D, d M Y H:i:s", strtotime($date_add)) . '</pubDate>
Expand Down
10 changes: 10 additions & 0 deletions modman
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
controllers/admin/* modules/smailyforprestashop/controllers/admin
controllers/front/* modules/smailyforprestashop/controllers/front
translations/* modules/smailyforprestashop/translations
upgrade/* modules/smailyforprestashop/upgrade
views/js/* modules/smailyforprestashop/views/js
views/templates/admin/* modules/smailyforprestashop/views/templates/admin
views/templates/hook/* modules/smailyforprestashop/views/templates/hook
index.php modules/smailyforprestashop/index.php
smailyforprestashop.php modules/smailyforprestashop/smailyforprestashop.php
logo.png modules/smailyforprestashop/logo.png
96 changes: 90 additions & 6 deletions smailyforprestashop.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct()
{
$this->name = 'smailyforprestashop';
$this->tab = 'advertising_marketing';
$this->version = '1.3.0';
$this->version = '1.4.0';
$this->author = 'Smaily';
$this->need_instance = 0;
$this->ps_versions_compliancy = array(
Expand All @@ -50,6 +50,8 @@ public function __construct()
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
}

public static $allowed_sort_by_values = array('date_add', 'date_upd', 'name', 'price', 'id_product');

public function install()
{
// Check if multistore is enabled
Expand All @@ -72,6 +74,10 @@ public function install()
!Configuration::updateValue('SMAILY_ABANDONED_CART_TIME', '') ||
!Configuration::updateValue('SMAILY_SYNCRONIZE_ADDITIONAL', serialize(array())) ||
!Configuration::updateValue('SMAILY_CART_SYNCRONIZE_ADDITIONAL', serialize(array())) ||
!Configuration::updateValue('SMAILY_RSS_CATEGORY_ID', '') ||
!Configuration::updateValue('SMAILY_RSS_LIMIT', '50') ||
!Configuration::updateValue('SMAILY_RSS_SORT_BY', 'date_upd') ||
!Configuration::updateValue('SMAILY_RSS_SORT_ORDER', 'desc') ||
// Add tab to sidebar
!$this->installTab('AdminAdmin', 'AdminSmailyforprestashopAjax', 'Smaily for PrestaShop') ||
// Add Newsletter subscription form.
Expand Down Expand Up @@ -122,6 +128,10 @@ public function uninstall()
!Configuration::deleteByName('SMAILY_ABANDONED_CART_TIME') ||
!Configuration::deleteByName('SMAILY_SYNCRONIZE_ADDITIONAL') ||
!Configuration::deleteByName('SMAILY_CART_SYNCRONIZE_ADDITIONAL') ||
!Configuration::deleteByName('SMAILY_RSS_CATEGORY_ID') ||
!Configuration::deleteByName('SMAILY_RSS_LIMIT') ||
!Configuration::deleteByName('SMAILY_RSS_SORT_BY') ||
!Configuration::deleteByName('SMAILY_RSS_SORT_ORDER') ||
// Remove sideTab of smaily module.
!$this->uninstallTab('AdminSmailyforprestashopAjax')
) {
Expand Down Expand Up @@ -251,6 +261,28 @@ public function getContent()
$output .= $this->displayConfirmation($this->l('Abandoned cart settings updated'));
}
}
// RSS
if (Tools::isSubmit('smaily_submit_rss')) {
// Update settings.
$category_id = (int) Tools::getValue('SMAILY_RSS_CATEGORY_ID');
$category_id = $category_id <= 0 ? false : $category_id;
Configuration::updateValue('SMAILY_RSS_CATEGORY_ID', $category_id);

$limit = (int) Tools::getValue('SMAILY_RSS_LIMIT');
$limit = $limit >= 1 && $limit <= 250 ? $limit : 50;
Configuration::updateValue('SMAILY_RSS_LIMIT', $limit);

$sort_by = Tools::getValue('SMAILY_RSS_SORT_BY');
$sort_by = in_array($sort_by, SmailyForPrestashop::$allowed_sort_by_values, true) ? $sort_by : 'date_upd';
Configuration::updateValue('SMAILY_RSS_SORT_BY', $sort_by);

$sort_order = Tools::getValue('SMAILY_RSS_SORT_ORDER');
$sort_order = in_array($sort_order, array('asc', 'desc'), true) ? $sort_order : 'desc';
Configuration::updateValue('SMAILY_RSS_SORT_ORDER', $sort_order);

// Display success message.
$output .= $this->displayConfirmation($this->l('RSS settings updated'));
}

// Get syncronize additional values for template.
if (false !== unserialize(Configuration::get('SMAILY_SYNCRONIZE_ADDITIONAL'))) {
Expand Down Expand Up @@ -280,13 +312,14 @@ public function getContent()
$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);

$categories = Category::getNestedCategories(null, Context::getContext()->language->id);

// Assign variables to template if available.
$this->context->smarty->assign(
array(
'smaily_enable_cron' => pSQL(Configuration::get('SMAILY_ENABLE_CRON')),
'smaily_enable_abandoned_cart' => pSQL(Configuration::get('SMAILY_ENABLE_ABANDONED_CART')),
'smaily_customer_cron_token' => $customer_cron_token,
'smaily_cart_cron_token' => $cart_cron_token,
'smaily_subdomain' => pSQL(Configuration::get('SMAILY_SUBDOMAIN')),
'smaily_username' => pSQL(Configuration::get('SMAILY_USERNAME')),
'smaily_password' => pSQL(Configuration::get('SMAILY_PASSWORD')),
Expand All @@ -295,21 +328,71 @@ public function getContent()
'smaily_syncronize_additional' => $sync_array,
'smaily_cart_syncronize_additional' => $cart_sync_array,
'token' => Tools::getAdminTokenLite('AdminSmailyforprestashopAjax'),
'smaily_rssfeed_url' => Context::getContext()->link->getModuleLink('smailyforprestashop', 'SmailyRssFeed'),
'smaily_rssfeed_url' => $this->buildRssUrlFromSettings(),
'smaily_customer_cron_url' => Context::getContext()->link->getModuleLink(
'smailyforprestashop',
'SmailyCustomerCron'
'SmailyCustomerCron',
array('token' => $customer_cron_token)
),
'smaily_cart_cron_url' => Context::getContext()->link->getModuleLink(
'smailyforprestashop',
'SmailyCartCron'
'SmailyCartCron',
array('token' => $cart_cron_token)
),
'smaily_rss_available_category_ids' => $this->recursivelyNormalizeCategoriesForTemplate($categories),
'smaily_rss_selected_category_id' => pSQL(Configuration::get('SMAILY_RSS_CATEGORY_ID')),
'smaily_rss_limit' => pSQL(Configuration::get('SMAILY_RSS_LIMIT')),
'smaily_rss_sort_by' => pSQL(Configuration::get('SMAILY_RSS_SORT_BY')),
'smaily_rss_sort_order' => pSQL(Configuration::get('SMAILY_RSS_SORT_ORDER')),
)
);
// Display settings form.
return $output .= $this->display(__FILE__, 'views/templates/admin/smaily_configure.tpl');
}

/**
* Recursively go through categories in array and normalize for template.
*
* @param array $categories Enabled categories in Prestashop catalog.
*
* @return array Categories in format: array(category id => category name).
*/
private function recursivelyNormalizeCategoriesForTemplate($categories)
{
$normalized = array();
foreach ( $categories as $category ) {
$normalized[$category['id_category']] = $category['name'];
if (isset($category['children']) && is_array($category['children'])) {
$normalized += $this->recursivelyNormalizeCategoriesForTemplate($category['children']);
}
}
return $normalized;
}

/**
* Make RSS URL with query parameters.
*
* @return string $url
* e.g example.com/en/module/smailyforprestashop/SmailyRssFeed?limit=50&sort_by=date_upd&sort_order=desc&category_id=2
*/
private function buildRssUrlFromSettings()
{
$query_arguments = array(
'limit' => Configuration::get('SMAILY_RSS_LIMIT'),
'sort_by' => Configuration::get('SMAILY_RSS_SORT_BY'),
'sort_order' => Configuration::get('SMAILY_RSS_SORT_ORDER'),
);
if (Configuration::get('SMAILY_RSS_CATEGORY_ID') !== '') {
$query_arguments['category_id'] = Configuration::get('SMAILY_RSS_CATEGORY_ID');
}

return Context::getContext()->link->getModuleLink(
'smailyforprestashop',
'SmailyRssFeed',
$query_arguments
);
}

// Display Block Newsletter in footer.
public function hookDisplayFooterBefore($params)
{
Expand Down Expand Up @@ -348,6 +431,7 @@ public function hookDisplayBackOfficeHeader()
Media::addJsDef(
array(
'controller_url' => $this->context->link->getAdminLink($this->controllerAdmin),
'smaily_rss_url' => Context::getContext()->link->getModuleLink('smailyforprestashop', 'SmailyRssFeed'),
'smailymessages' => array(
'no_autoresponders' => $this->l('No autoresponders created in Smaily!'),
'no_connection' => $this->l('There seems to be some problem with connecting to Smaily!'),
Expand Down
Loading

0 comments on commit 2817114

Please sign in to comment.