Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
luciobenini committed Sep 12, 2020
0 parents commit e4f68c9
Show file tree
Hide file tree
Showing 17 changed files with 1,232 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Private files
# The following files contain your database credentials and other personal data.

config/settings.*.php

# Cache, temp and generated files
# The following files are generated by PrestaShop.

admin-dev/autoupgrade/
/cache/*
!/cache/index.php
!/cache/*/
/cache/*/*
!/cache/cachefs/index.php
!/cache/purifier/index.php
!/cache/push/index.php
!/cache/sandbox/index.php
!/cache/smarty/index.php
!/cache/tcpdf/index.php
config/xml/*.xml
/log/*
*sitemap.xml
themes/*/cache/
modules/*/config*.xml

# Site content
# The following folders contain product images, virtual products, CSV's, etc.

admin-dev/backups/
admin-dev/export/
admin-dev/import/
download/
/img/*
upload/
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# pittica/prestashop-nutritionalfacts

![License](https://img.shields.io/github/license/pittica/prestashop-nutritionalfacts)
![Release](https://img.shields.io/github/v/release/pittica/prestashop-nutritionalfacts)

Nutritional Facts module for [PrestaShop](https://github.com/prestashop/prestashop).

## Requirements

[PrestaShop](https://github.com/prestashop/prestashop) version 1.7 or newer.

## Copyright

(c) 2020, Pittaca S.r.l.s.

40 changes: 40 additions & 0 deletions classes/ProductNutritionalFacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* 2020 Pittica S.r.l.s.
*
* @author Lucio Benini <info@pittica.com>
* @copyright 2020 Pittica S.r.l.s.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
*/

class ProductNutritionalFacts extends ObjectModel
{
const TABLE_NAME = 'pittica_nutritionalfacts';

public $id_product;
public $composition_unit;
public $composition;
public $additives_unit;
public $additives;
public $analysis_unit;
public $analysis;
public $additional_data;
public $quantity;

public static $definition = array(
'table' => self::TABLE_NAME,
'primary' => 'id_product',
'multilang' => true,
'fields' => array(
'id_product' => array( 'type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true ),
'composition_unit' => array( 'type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => false, 'size' => 254, 'lang' => true ),
'composition' => array( 'type' => self::TYPE_HTML, 'validate' => 'isString', 'required' => false, 'lang' => true ),
'additives_unit' => array( 'type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => false, 'size' => 254, 'lang' => true ),
'additives' => array( 'type' => self::TYPE_HTML, 'validate' => 'isString', 'required' => false, 'lang' => true ),
'analysis_unit' => array( 'type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => false, 'size' => 254, 'lang' => true ),
'analysis' => array( 'type' => self::TYPE_HTML, 'validate' => 'isString', 'required' => false, 'lang' => true ),
'additional_data' => array( 'type' => self::TYPE_HTML, 'validate' => 'isString', 'required' => false, 'lang' => true ),
'quantity' => array( 'type' => self::TYPE_HTML, 'validate' => 'isString', 'required' => false, 'lang' => true )
)
);
}
8 changes: 8 additions & 0 deletions classes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php/** * 2020 Pittica S.r.l.s. * * @author Lucio Benini <info@pittica.com> * @copyright 2020 Pittica S.r.l.s. * @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 (LGPL-3.0) */
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;
Expand Down
34 changes: 34 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions pitticanutritionalfacts.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
154 changes: 154 additions & 0 deletions pitticanutritionalfacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php

/**
* 2020 Pittica S.r.l.s.
*
* @author Lucio Benini <info@pittica.com>
* @copyright 2020 Pittica S.r.l.s.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
*/

if (!defined('_PS_VERSION_')) {
exit;
}

require_once(dirname(__FILE__) . '/classes/ProductNutritionalFacts.php');

class PitticaNutritionalFacts extends Module
{
protected $config_form = false;

public function __construct()
{
$this->name = 'pitticanutritionalfacts';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Pittica';
$this->need_instance = 1;

parent::__construct();

$this->displayName = $this->l('Nutritional Facts');
$this->description = $this->l('Nutritional facts and additional data.');

$this->ps_versions_compliancy = array(
'min' => '1.7',
'max' => _PS_VERSION_
);
}

public function install()
{
include(dirname(__FILE__) . '/sql/install.php');

return parent::install() && $this->registerHook('actionProductAdd') && $this->registerHook('actionProductUpdate') && $this->registerHook('actionProductDelete') && $this->registerHook('displayAdminProductsMainStepLeftColumnBottom') && $this->registerHook('displayFooterProduct');
}

public function uninstall()
{
include(dirname(__FILE__) . '/sql/uninstall.php');

return parent::uninstall();
}

public function hookActionProductDelete($params)
{
if (isset($params['id_product'])) {
$object = new ProductNutritionalFacts($params['id_product']);
$object->delete();
}
}

public function hookActionProductAdd($params)
{
if (isset($params['id_product'])) {
if (isset($params['id_product_old'])) {
$old = new ProductNutritionalFacts((int) $params['id_product_old']);
$new = new ProductNutritionalFacts((int) $params['id_product']);

$values = $this->getValues();

$new->id_product = (int) $params['id_product'];
$new->composition_unit = $old->composition_unit;
$new->composition = $old->composition;
$new->additives_unit = $old->additives_unit;
$new->additives = $old->additives;
$new->analysis_unit = $old->analysis_unit;
$new->analysis = $old->analysis;
$new->additional_data = $old->additional_data;
$new->quantity = $old->quantity;

$new->save();
} else {
$this->fillObject((int) $params['id_product']);
}
}
}

public function hookActionProductUpdate($params)
{
if (isset($params['id_product'])) {
$this->fillObject((int) $params['id_product']);
}
}

public function hookDisplayFooterProduct($params)
{
$this->context->smarty->assign('nutritionfacts', new ProductNutritionalFacts((int) Tools::getValue('id_product'), (int) Configuration::get('PS_LANG_DEFAULT')));

return $this->fetch('module:' . $this->name . '/views/templates/hook/displayFooterProduct.tpl');
}

public function hookDisplayAdminProductsMainStepLeftColumnBottom($params)
{
$this->context->smarty->assign(array(
'languages' => Language::getLanguages(true),
'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'),
'nutritionfacts' => new ProductNutritionalFacts((int) $params['id_product'])
));

return $this->fetch('module:' . $this->name . '/views/templates/hook/displayAdminProductsMainStepLeftColumnBottom.tpl');
}

private function fillObject($id_product)
{
$values = $this->getValues();

$object = new ProductNutritionalFacts((int) $id_product);
$object->id_product = (int) $id_product;
$object->composition_unit = $values['composition_unit'];
$object->composition = $values['composition'];
$object->additives_unit = $values['additives_unit'];
$object->additives = $values['additives'];
$object->analysis_unit = $values['analysis_unit'];
$object->analysis = $values['analysis'];
$object->additional_data = $values['additional_data'];
$object->quantity = $values['quantity'];

$object->save();
}

private function getValues()
{
$values = array(
'composition_unit' => '',
'composition' => '',
'additives_unit' => '',
'additives' => '',
'analysis_unit' => '',
'analysis' => '',
'additional_data' => '',
'quantity' => ''
);

$form = Tools::getValue('nutritionfacts');

foreach ($values as $key => &$value) {
if (isset($form[$key])) {
$value = $form[$key];
}
}

return $values;
}
}
8 changes: 8 additions & 0 deletions sql/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php/** * 2020 Pittica S.r.l.s. * * @author Lucio Benini <info@pittica.com> * @copyright 2020 Pittica S.r.l.s. * @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 (LGPL-3.0) */
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;
Expand Down
33 changes: 33 additions & 0 deletions sql/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* 2020 Pittica S.r.l.s.
*
* @author Lucio Benini <info@pittica.com>
* @copyright 2020 Pittica S.r.l.s.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 (LGPL-3.0)
*/

$sql = array();

$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . ProductNutritionalFacts::TABLE_NAME . '` (
`id_product` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . ProductNutritionalFacts::TABLE_NAME . '_lang` (
`id_product` INT(10) UNSIGNED NOT NULL,
`id_lang` INT(10) UNSIGNED NOT NULL,
`composition_unit` TEXT NULL,
`additives_unit` TEXT NULL,
`analysis_unit` TEXT NULL,
`composition` TEXT NULL,
`additives` TEXT NULL,
`analysis` TEXT NULL,
`additional_data` TEXT NULL,
`quantity` TEXT NULL,
PRIMARY KEY (`id_product`, `id_lang`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';

foreach ($sql as $query) {
if (Db::getInstance()->execute($query) == false) {
return false;
}
}
18 changes: 18 additions & 0 deletions sql/uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* 2020 Pittica S.r.l.s.
*
* @author Lucio Benini <info@pittica.com>
* @copyright 2020 Pittica S.r.l.s.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 (LGPL-3.0)
*/

$sql = array();
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . ProductNutritionalFacts::TABLE_NAME . '`;';
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . ProductNutritionalFacts::TABLE_NAME . '_lang`;';

foreach ($sql as $query) {
if (Db::getInstance()->execute($query) == false) {
return false;
}
}
Loading

0 comments on commit e4f68c9

Please sign in to comment.