Skip to content

Commit

Permalink
Merge pull request #84 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
Progi1984 authored Apr 1, 2021
2 parents 7ced3b6 + 332d618 commit b8846d4
Show file tree
Hide file tree
Showing 36 changed files with 2,167 additions and 589 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build
on:
push:
branches:
- master

jobs:
deploy:
name: build dependencies & create artifact
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

# Install PHP dependencies (Production ONLY)
- name: Install composer dependencies
run: composer install --no-dev -o

# Remove development files
- name: Clean-up project
uses: PrestaShopCorp/[email protected]

# Zip files and upload to artifacts list
- name: Create & upload artifact
uses: actions/upload-artifact@v1
with:
name: ${{ github.event.repository.name }}
path: ../
75 changes: 75 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: PHP tests
on: [push, pull_request]
jobs:
# Check there is no syntax errors in the project
php-linter:
name: PHP Syntax check 5.6|7.2|7.3
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@master

- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master

- name: PHP syntax checker 7.3
uses: prestashop/github-action-php-lint/7.3@master

# Check the PHP code follow the coding standards
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Checkout
uses: actions/[email protected]

- name: Cache dependencies
uses: actions/cache@v2
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

- name: Install dependencies
run: composer install

- name: Run PHP-CS-Fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no --diff-format udiff

# Run PHPStan against the module and a PrestaShop release
phpstan:
name: PHPStan
runs-on: ubuntu-latest
strategy:
matrix:
presta-versions: ['1.7.6.9', 'latest']
steps:
- name: Checkout
uses: actions/[email protected]

# Add vendor folder in cache to make next builds faster
- name: Cache vendor folder
uses: actions/cache@v1
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

# Add composer local folder in cache to make next builds faster
- name: Cache composer folder
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: php-composer-cache

- run: composer install

# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled
- name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }})
run: ./tests/php/phpstan.sh ${{ matrix.presta-versions }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor
.php_cs.cache
11 changes: 11 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$config = new PrestaShop\CodingStandards\CsFixer\Config();

$config
->setUsingCache(true)
->getFinder()
->in(__DIR__)
->exclude('vendor');

return $config;
107 changes: 53 additions & 54 deletions MailAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ class MailAlert extends ObjectModel
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
public static $definition = [
'table' => 'mailalert_customer_oos',
'primary' => 'id_customer',
'fields' => array(
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
'customer_email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true),
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
'id_product_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
),
);
'fields' => [
'id_customer' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
'customer_email' => ['type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true],
'id_product' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
'id_product_attribute' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
'id_shop' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
'id_lang' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
],
];

public static function customerHasNotification($id_customer, $id_product, $id_product_attribute, $id_shop = null, $id_lang = null, $guest_email = '')
{
Expand All @@ -72,24 +72,24 @@ public static function customerHasNotification($id_customer, $id_product, $id_pr
$where = $id_customer == 0 ? "customer_email = '$guest_email'" : "(id_customer=$id_customer OR customer_email='$customer_email')";
$sql = '
SELECT *
FROM `'._DB_PREFIX_.self::$definition['table'].'`
WHERE '.$where.'
AND `id_product` = '.(int) $id_product.'
AND `id_product_attribute` = '.(int) $id_product_attribute.'
AND `id_shop` = '.(int) $id_shop;
FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
WHERE ' . $where . '
AND `id_product` = ' . (int) $id_product . '
AND `id_product_attribute` = ' . (int) $id_product_attribute . '
AND `id_shop` = ' . (int) $id_shop;

return count(Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql));
}

public static function deleteAlert($id_customer, $customer_email, $id_product, $id_product_attribute, $id_shop = null)
{
$sql = '
DELETE FROM `'._DB_PREFIX_.self::$definition['table'].'`
WHERE '.(($id_customer > 0) ? '(`customer_email` = \''.pSQL($customer_email).'\' OR `id_customer` = '.(int) $id_customer.')' :
'`customer_email` = \''.pSQL($customer_email).'\'').
' AND `id_product` = '.(int) $id_product.'
AND `id_product_attribute` = '.(int) $id_product_attribute.'
AND `id_shop` = '.($id_shop != null ? (int) $id_shop : (int) Context::getContext()->shop->id);
DELETE FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
WHERE ' . (($id_customer > 0) ? '(`customer_email` = \'' . pSQL($customer_email) . '\' OR `id_customer` = ' . (int) $id_customer . ')' :
'`customer_email` = \'' . pSQL($customer_email) . '\'') .
' AND `id_product` = ' . (int) $id_product . '
AND `id_product_attribute` = ' . (int) $id_product_attribute . '
AND `id_shop` = ' . ($id_shop != null ? (int) $id_shop : (int) Context::getContext()->shop->id);

return Db::getInstance()->execute($sql);
}
Expand All @@ -100,7 +100,7 @@ public static function deleteAlert($id_customer, $customer_email, $id_product, $
public static function getMailAlerts($id_customer, $id_lang, Shop $shop = null)
{
if (!Validate::isUnsignedId($id_customer) || !Validate::isUnsignedId($id_lang)) {
die(Tools::displayError());
exit(Tools::displayError());
}

if (!$shop) {
Expand All @@ -112,7 +112,7 @@ public static function getMailAlerts($id_customer, $id_lang, Shop $shop = null)
$products_number = count($products);

if (empty($products) === true || !$products_number) {
return array();
return [];
}

for ($i = 0; $i < $products_number; ++$i) {
Expand All @@ -128,7 +128,7 @@ public static function getMailAlerts($id_customer, $id_lang, Shop $shop = null)

if ($attributes) {
foreach ($attributes as $row) {
$products[$i]['attributes_small'] .= $row['attribute_name'].', ';
$products[$i]['attributes_small'] .= $row['attribute_name'] . ', ';
}
}

Expand All @@ -140,7 +140,7 @@ public static function getMailAlerts($id_customer, $id_lang, Shop $shop = null)
foreach ($attrgrps as $attrgrp) {
if ($attrgrp['id_product_attribute'] == (int) $products[$i]['id_product_attribute']
&& $images = Product::_getAttributeImageAssociations((int) $attrgrp['id_product_attribute'])) {
$products[$i]['cover'] = $obj->id.'-'.array_pop($images);
$products[$i]['cover'] = $obj->id . '-' . array_pop($images);
break;
}
}
Expand All @@ -150,14 +150,14 @@ public static function getMailAlerts($id_customer, $id_lang, Shop $shop = null)
$images = $obj->getImages((int) $id_lang);
foreach ($images as $image) {
if ($image['cover']) {
$products[$i]['cover'] = $obj->id.'-'.$image['id_image'];
$products[$i]['cover'] = $obj->id . '-' . $image['id_image'];
break;
}
}
}

if (!isset($products[$i]['cover'])) {
$products[$i]['cover'] = Language::getIsoById($id_lang).'-default';
$products[$i]['cover'] = Language::getIsoById($id_lang) . '-default';
}
$products[$i]['link'] = $obj->getLink();
$context = Context::getContext();
Expand All @@ -182,10 +182,10 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)
$product = new Product((int) $id_product, false, $id_lang, $id_shop);
$product_name = Product::getProductName($product->id, $id_product_attribute, $id_lang);
$product_link = $link->getProductLink($product, $product->link_rewrite, null, null, $id_lang, $id_shop, $id_product_attribute);
$template_vars = array(
$template_vars = [
'{product}' => $product_name,
'{product_link}' => $product_link,
);
];

if ($customer['id_customer']) {
$customer = new Customer((int) $customer['id_customer']);
Expand All @@ -201,22 +201,21 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)

$translator = Context::getContext()->getTranslatorFromLocale($locale);

if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.txt') &&
file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.html')) {

if (file_exists(dirname(__FILE__) . '/mails/' . $iso . '/customer_qty.txt') &&
file_exists(dirname(__FILE__) . '/mails/' . $iso . '/customer_qty.html')) {
try {
Mail::Send(
$id_lang,
'customer_qty',
$translator->trans('Product available', array(), 'Emails.Subject', $locale),
$translator->trans('Product available', [], 'Emails.Subject', $locale),
$template_vars,
(string) $customer_email,
null,
(string) Configuration::get('PS_SHOP_EMAIL', null, null, $id_shop),
(string) Configuration::get('PS_SHOP_NAME', null, null, $id_shop),
null,
null,
dirname(__FILE__).'/mails/',
dirname(__FILE__) . '/mails/',
false,
$id_shop
);
Expand All @@ -238,12 +237,12 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)

Hook::exec(
'actionModuleMailAlertSendCustomer',
array(
[
'product' => $product_name,
'link' => $product_link,
'customer' => $customer,
'product_obj' => $product,
)
]
);

self::deleteAlert(
Expand All @@ -259,9 +258,9 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)
/*
* Generate correctly the address for an email
*/
public static function getFormatedAddress(Address $address, $line_sep, $fields_style = array())
public static function getFormatedAddress(Address $address, $line_sep, $fields_style = [])
{
return AddressFormat::generateAddress($address, array('avoid' => array()), $line_sep, ' ', $fields_style);
return AddressFormat::generateAddress($address, ['avoid' => []], $line_sep, ' ', $fields_style);
}

/*
Expand All @@ -273,13 +272,13 @@ public static function getProducts($customer, $id_lang)

$sql = '
SELECT ma.`id_product`, p.`quantity` AS product_quantity, pl.`name`, ma.`id_product_attribute`
FROM `'._DB_PREFIX_.self::$definition['table'].'` ma
JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = ma.`id_product`)
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.id_shop IN ('.implode(', ', $list_shop_ids).'))
FROM `' . _DB_PREFIX_ . self::$definition['table'] . '` ma
JOIN `' . _DB_PREFIX_ . 'product` p ON (p.`id_product` = ma.`id_product`)
' . Shop::addSqlAssociation('product', 'p') . '
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.id_shop IN (' . implode(', ', $list_shop_ids) . '))
WHERE product_shop.`active` = 1
AND (ma.`id_customer` = '.(int) $customer->id.' OR ma.`customer_email` = \''.pSQL($customer->email).'\')
AND pl.`id_lang` = '.(int) $id_lang.Shop::addSqlRestriction(false, 'ma');
AND (ma.`id_customer` = ' . (int) $customer->id . ' OR ma.`customer_email` = \'' . pSQL($customer->email) . '\')
AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestriction(false, 'ma');

return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
Expand All @@ -291,14 +290,14 @@ public static function getProductAttributeCombination($id_product_attribute, $id
{
$sql = '
SELECT al.`name` AS attribute_name
FROM `'._DB_PREFIX_.'product_attribute_combination` pac
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON (a.`id_attribute` = pac.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int) $id_lang.')
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int) $id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
'.Shop::addSqlAssociation('product_attribute', 'pa').'
WHERE pac.`id_product_attribute` = '.(int) $id_product_attribute;
FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac
LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON (a.`id_attribute` = pac.`id_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . (int) $id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = ' . (int) $id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
' . Shop::addSqlAssociation('product_attribute', 'pa') . '
WHERE pac.`id_product_attribute` = ' . (int) $id_product_attribute;

return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
Expand All @@ -310,8 +309,8 @@ public static function getCustomers($id_product, $id_product_attribute)
{
$sql = '
SELECT id_customer, customer_email, id_shop, id_lang
FROM `'._DB_PREFIX_.self::$definition['table'].'`
WHERE `id_product` = '.(int) $id_product.' AND `id_product_attribute` = '.(int) $id_product_attribute;
FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
WHERE `id_product` = ' . (int) $id_product . ' AND `id_product_attribute` = ' . (int) $id_product_attribute;

return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Make your everyday life easier, handle mail alerts about stock and orders, addre

This module is partially compatible with the multistore feature. Some of its options might not be available.

## Reporting issues

You can report issues with this module in the main PrestaShop repository. [Click here to report an issue][report-issue].

## Contributing

PrestaShop modules are open source extensions to the [PrestaShop e-commerce platform][prestashop]. Everyone is welcome and even encouraged to contribute with their own improvements!
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
}
],
"require": {
"php": ">=5.4"
"php": ">=5.6",
"prestashop/php-dev-tools": "^3.15"
},
"config": {
"preferred-install": "dist"
"platform": {
"php": "5.6.0"
},
"preferred-install": "dist",
"prepend-autoloader": false
},
"type": "prestashop-module"
}
Loading

0 comments on commit b8846d4

Please sign in to comment.