Skip to content

Commit

Permalink
New: #15 Make the dolibarr version mandatory into label of any product
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Sep 14, 2016
1 parent 32845c9 commit 833fefe
Show file tree
Hide file tree
Showing 17 changed files with 498 additions and 61 deletions.
40 changes: 34 additions & 6 deletions dolistore/modules/blockmysales/blockmysales.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ public function install()

public function installSql()
{
$dolibarr_min = Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product` ADD COLUMN IF NOT EXISTS `dolibarr_min` varchar(6)');
$dolibarr_max = Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product` ADD COLUMN IF NOT EXISTS `dolibarr_max` varchar(6)');
$module_version = Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product` ADD COLUMN IF NOT EXISTS `module_version` varchar(7)');
$dolibarr_min = Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product` ADD COLUMN IF NOT EXISTS `dolibarr_min` varchar(5)');
$dolibarr_min_status = Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product` ADD COLUMN IF NOT EXISTS `dolibarr_min_status` tinyint(1) DEFAULT 0');
$dolibarr_max = Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product` ADD COLUMN IF NOT EXISTS `dolibarr_max` varchar(5)');
$dolibarr_max_status = Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product` ADD COLUMN IF NOT EXISTS `dolibarr_max_status` tinyint(1) DEFAULT 0');

return ($dolibarr_min & $dolibarr_max);
return ($module_version & $dolibarr_min & $dolibarr_min_status & $dolibarr_max & $dolibarr_max_status);
}

public function uninstall()
Expand Down Expand Up @@ -941,13 +944,24 @@ public function addProduct($customer)
$qty=0;
}

// Module version
$module_version = (Tools::isSubmit('module_version') ? Tools::getValue('module_version') : null);

// Dolibarr min/max compatibility
$dolibarr_min = (Tools::isSubmit('dolibarr_min') ? Tools::getValue('dolibarr_min') : null);
$dolibarr_min_status = (Tools::isSubmit('dolibarr_min_status') ? Tools::getValue('dolibarr_min_status') : 0);
$dolibarr_max = (Tools::isSubmit('dolibarr_max') ? Tools::getValue('dolibarr_max') : null);
$dolibarr_max_status = (Tools::isSubmit('dolibarr_max_status') ? Tools::getValue('dolibarr_max_status') : 0);

//insertion du produit en base
$query = 'INSERT INTO `'._DB_PREFIX_.'product` (
`id_supplier`, `id_manufacturer`, `id_tax_rules_group`, `id_category_default`, `on_sale`, `ean13`, `ecotax`, `is_virtual`,
`quantity`, `price`, `wholesale_price`, `reference`, `supplier_reference`, `location`, `weight`, `out_of_stock`,
`quantity_discount`, `customizable`, `uploadable_files`, `text_fields`, `active`, `indexed`, `date_add`, `date_upd`
`quantity_discount`, `customizable`, `uploadable_files`, `text_fields`, `active`, `indexed`, `date_add`, `date_upd`,
`module_version`, `dolibarr_min`, `dolibarr_min_status`, `dolibarr_max`, `dolibarr_max_status`
) VALUES (
0, 0, '.$taxe_id.', '.$id_categorie_default.', 0, 0, 0.00, 1, '.$qty.', '.$prix_ht.', '.$prix_ht.', \''.$reference.'\', \'\', \'\', 0, 0, 0, 0, 0, 0, '.$status.', 1, \''.$dateNow.'\', \''.$dateNow.'\'
0, 0, '.$taxe_id.', '.$id_categorie_default.', 0, 0, 0.00, 1, '.$qty.', '.$prix_ht.', '.$prix_ht.', \''.$reference.'\', \'\', \'\', 0, 0, 0, 0, 0, 0,
'.$status.', 1, \''.$dateNow.'\', \''.$dateNow.'\', \''.$module_version.'\', \''.$dolibarr_min.'\', '.$dolibarr_min_status.', \''.$dolibarr_max.'\', '.$dolibarr_max_status.'
)';

$result = Db::getInstance()->Execute($query);
Expand Down Expand Up @@ -1246,14 +1260,28 @@ public function updateProduct($id_product, $customer)
$qty=0;
}

// Module version
$module_version = (Tools::isSubmit('module_version') ? Tools::getValue('module_version') : null);

// Dolibarr min/max compatibility
$dolibarr_min = (Tools::isSubmit('dolibarr_min') ? Tools::getValue('dolibarr_min') : null);
$dolibarr_min_status = (Tools::isSubmit('dolibarr_min_status') ? Tools::getValue('dolibarr_min_status') : 0);
$dolibarr_max = (Tools::isSubmit('dolibarr_max') ? Tools::getValue('dolibarr_max') : null);
$dolibarr_max_status = (Tools::isSubmit('dolibarr_max_status') ? Tools::getValue('dolibarr_max_status') : 0);

//Mise a jour du produit en base
$query = 'UPDATE `'._DB_PREFIX_.'product` SET
`id_category_default` = '.$id_categorie_default.',
`quantity` = '.$qty.',
`price` = '.$prix_ht.',
`wholesale_price` = '.$prix_ht.',
`id_tax_rules_group` = '.$taxe_id.',
`reference` = \''.$reference.'\',';
`reference` = \''.$reference.'\',
`module_version` = \''.$module_version.'\',
`dolibarr_min` = \''.$dolibarr_min.'\',
`dolibarr_min_status` = '.$dolibarr_min_status.',
`dolibarr_max` = \''.$dolibarr_max.'\',
`dolibarr_max_status` = '.$dolibarr_max_status.',';
if ($status >= 0) $query.= ' `active` = '.$status.','; // We don't change if status is -1
if ($oldPrice == 0 && $newPrice > 0) {
$query.= ' `available_for_order` = 1, `show_price` = 1, `cache_has_attachments` = 0,';
Expand Down
15 changes: 10 additions & 5 deletions dolistore/modules/blockmysales/controllers/front/cardproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,23 @@ public function displayContent()

//recupération des informations
$query = 'SELECT
`id_supplier`, `id_manufacturer`, `id_category_default`, `on_sale`, `ean13`, `ecotax`, `quantity`, `price`, `wholesale_price`,
`id_supplier`, `id_manufacturer`, `id_category_default`, `on_sale`, `ean13`, `ecotax`, `quantity`, `price`, `wholesale_price`, `module_version`, `dolibarr_min`, `dolibarr_min_status`, `dolibarr_max`, `dolibarr_max_status`,
`reference`, `supplier_reference`, `location`, `weight`, `out_of_stock`, `quantity_discount`, `customizable`, `uploadable_files`, `text_fields`, `active`, `indexed`, `date_add`, `date_upd`
FROM `'._DB_PREFIX_.'product`
WHERE `id_product` = '.$product_id.' ';
$result = Db::getInstance()->ExecuteS($query);
if ($result === false) die(Tools::displayError('Invalid loadLanguage() SQL query!: '.$query));
foreach ($result AS $row)
{
$product['price'] = round((Tools::isSubmit('price') ? Tools::getValue('price') : $row['price']), 2);
$product['wholesale_price'] = $row['wholesale_price'];
$product['active'] = $row['active'];
$product['reference'] = $row['reference'];
$product['price'] = round((Tools::isSubmit('price') ? Tools::getValue('price') : $row['price']), 2);
$product['wholesale_price'] = $row['wholesale_price'];
$product['active'] = $row['active'];
$product['reference'] = $row['reference'];
$product['module_version'] = $row['module_version'];
$product['dolibarr_min'] = $row['dolibarr_min'];
$product['dolibarr_min_status'] = $row['dolibarr_min_status'];
$product['dolibarr_max'] = $row['dolibarr_max'];
$product['dolibarr_max_status'] = $row['dolibarr_max_status'];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ public function displayContent()
'price' => (Tools::isSubmit('price') ? Tools::getValue('price') : 0),
'active' => 0,
'file_name' => Tools::getValue('product_file_name'),
'module_version' => Tools::getValue('dolibarr_min'),
'dolibarr_min' => Tools::getValue('dolibarr_min'),
'dolibarr_min_status' => (Tools::isSubmit('dolibarr_min_status') ? Tools::getValue('dolibarr_min_status') : 0),
'dolibarr_max' => Tools::getValue('dolibarr_max'),
'dolibarr_max_status' => (Tools::isSubmit('dolibarr_max_status') ? Tools::getValue('dolibarr_max_status') : 0),
'nb_days_accessible' => (Tools::isSubmit('nb_days_accessible') ? Tools::getValue('nb_days_accessible') : (!empty($nbdaysaccessible) ? $nbdaysaccessible : 365)),
'product_name' => array(),
'resume' => array(),
Expand Down Expand Up @@ -648,7 +653,7 @@ public function displayContent()
if (Tools::isSubmit('id_p') && is_numeric(Tools::getValue('id_p')))
{
// Get product id
$query = 'SELECT p.id_product, p.price, pl.description, pl.description_short, pl.meta_description, pl.meta_keywords, pl.meta_title, pl.name, pl.id_lang';
$query = 'SELECT p.id_product, p.price, p.module_version, p.dolibarr_min, p.dolibarr_min_status, p.dolibarr_max, p.dolibarr_max_status, pl.description, pl.description_short, pl.meta_description, pl.meta_keywords, pl.meta_title, pl.name, pl.id_lang';
$query.= ' FROM '._DB_PREFIX_.'product as p, '._DB_PREFIX_.'product_lang as pl, '._DB_PREFIX_.'lang as l WHERE l.id_lang = pl.id_lang AND p.id_product = pl.id_product AND p.id_product = '.((int) Tools::getValue('id_p'));
$result = Db::getInstance()->ExecuteS($query);
if ($result === false) die(Tools::displayError('Invalid loadLanguage() SQL query!: '.$query));
Expand All @@ -660,6 +665,11 @@ public function displayContent()
$newproduct['resume'][$row['id_lang']] = $row['description_short'];
$newproduct['description'][$row['id_lang']] = $row['description'];
$newproduct['price'] = round($row['price'], 2);
$newproduct['module_version'] = $row['module_version'];
$newproduct['dolibarr_min'] = $row['dolibarr_min'];
$newproduct['dolibarr_min_status'] = $row['dolibarr_min_status'];
$newproduct['dolibarr_max'] = $row['dolibarr_max'];
$newproduct['dolibarr_max_status'] = $row['dolibarr_max_status'];
}
}

Expand Down
8 changes: 8 additions & 0 deletions dolistore/modules/blockmysales/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
padding-top: 10px;
}

div.checker {
float: left;
}

#agreetoaddwikipagelabel, #agreewithtermofuselabel {
display: inherit;
}

.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited {
color: #555!important;
}
Expand Down
20 changes: 20 additions & 0 deletions dolistore/modules/blockmysales/override/classes/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
class Product extends ProductCore
{
public $module_version;
public $dolibarr_min;
public $dolibarr_min_status;
public $dolibarr_max;
public $dolibarr_max_status;

public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
Product::$definition['fields']['module_version'] = array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 7);
Product::$definition['fields']['dolibarr_min'] = array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 5);
Product::$definition['fields']['dolibarr_min_status'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');
Product::$definition['fields']['dolibarr_max'] = array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 5);
Product::$definition['fields']['dolibarr_max_status'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');

parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
}
}
35 changes: 35 additions & 0 deletions dolistore/modules/blockmysales/override/classes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2014 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-2014 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;
35 changes: 35 additions & 0 deletions dolistore/modules/blockmysales/override/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2014 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-2014 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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
if (!defined('_PS_VERSION_'))
exit;

class BlockViewedOverride extends BlockViewed
{
public function hookRightColumn($params)
{
$productsViewed = (isset($params['cookie']->viewed) && !empty($params['cookie']->viewed)) ? array_slice(array_reverse(explode(',', $params['cookie']->viewed)), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array();

if (count($productsViewed))
{
$defaultCover = Language::getIsoById($params['cookie']->id_lang).'-default';

$productIds = implode(',', array_map('intval', $productsViewed));
$productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT MAX(image_shop.id_image) id_image, p.id_product, p.dolibarr_min, p.dolibarr_min_status, p.dolibarr_max, p.dolibarr_max_status, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite
FROM '._DB_PREFIX_.'product p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)'.
Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = image_shop.id_image AND il.id_lang = '.(int)($params['cookie']->id_lang).')
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
WHERE p.id_product IN ('.$productIds.')
AND pl.id_lang = '.(int)($params['cookie']->id_lang).'
AND cl.id_lang = '.(int)($params['cookie']->id_lang).'
GROUP BY product_shop.id_product'
);

$productsImagesArray = array();
foreach ($productsImages as $pi)
$productsImagesArray[$pi['id_product']] = $pi;

$productsViewedObj = array();
foreach ($productsViewed as $productViewed)
{
$obj = (object)'Product';
if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active']))
continue;
else
{
$obj->id = (int)($productsImagesArray[$productViewed]['id_product']);
$obj->id_image = (int)$productsImagesArray[$productViewed]['id_image'];
$obj->cover = (int)($productsImagesArray[$productViewed]['id_product']).'-'.(int)($productsImagesArray[$productViewed]['id_image']);
$obj->legend = $productsImagesArray[$productViewed]['legend'];
$obj->name = $productsImagesArray[$productViewed]['name'];
$obj->description_short = $productsImagesArray[$productViewed]['description_short'];
$obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite'];
$obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite'];
// $obj is not a real product so it cannot be used as argument for getProductLink()
$obj->product_link = $this->context->link->getProductLink($obj->id, $obj->link_rewrite, $obj->category_rewrite);
$obj->dolibarr_min = $productsImagesArray[$productViewed]['dolibarr_min'];
$obj->dolibarr_min_status = $productsImagesArray[$productViewed]['dolibarr_min_status'];
$obj->dolibarr_max = $productsImagesArray[$productViewed]['dolibarr_max'];
$obj->dolibarr_max_status = $productsImagesArray[$productViewed]['dolibarr_max_status'];

if (!isset($obj->cover) || !$productsImagesArray[$productViewed]['id_image'])
{
$obj->cover = $defaultCover;
$obj->legend = '';
}
$productsViewedObj[] = $obj;
}
}

if (!count($productsViewedObj))
return;

$this->smarty->assign(array(
'productsViewedObj' => $productsViewedObj,
'mediumSize' => Image::getSize('medium')));

return $this->display(__FILE__, 'blockviewed.tpl');
}
return;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2014 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-2014 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;

0 comments on commit 833fefe

Please sign in to comment.