Rework on module
This commit is contained in:
parent
b21ec24c23
commit
d4edd05e5d
@ -40,8 +40,9 @@ class AntadisConfigurator extends Module
|
||||
return false;
|
||||
}
|
||||
|
||||
// Install AdminAntadisConfiguratorProduct
|
||||
if (!$this->installTab('AdminCatalog', 'AdminAntadisConfiguratorProduct', 'Configurator Product', 0)) {
|
||||
// Install AdminAntadisConfiguratorProductGroup AdminAntadisConfiguratorProductImpact
|
||||
if (!$this->installTab('AdminCatalog', 'AdminAntadisConfiguratorProductGroup', 'Configurator Product Group', 0) ||
|
||||
!$this->installTab('AdminCatalog', 'AdminAntadisConfiguratorProductImpact', 'Configurator Product Impact', 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ class ProductConfiguratorOptGroup extends ObjectModel
|
||||
public $required;
|
||||
public $position;
|
||||
|
||||
|
||||
public static $definition = array(
|
||||
'table' => 'product_configurator_opt_group',
|
||||
'primary' => 'id_product_configurator_opt_group',
|
||||
@ -43,23 +42,100 @@ class ProductConfiguratorOptGroup extends ObjectModel
|
||||
WHERE `id_configurator_opt_group` = '.(int)$this->id_configurator_opt_group.' AND `id_lang` = '.(int)$id_lang);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move an attribute inside its group
|
||||
* @param bool $way Up (1) or Down (0)
|
||||
* @param int $position
|
||||
* @return bool Update result
|
||||
*/
|
||||
public function updatePosition($way, $position)
|
||||
{
|
||||
if (!$id_product = (int)Tools::getValue('id_product')) {
|
||||
$id_product = (int)$this->id_product;
|
||||
}
|
||||
|
||||
$sql = '
|
||||
SELECT a.`id_product_configurator_opt_group`, a.`position`, a.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product_configurator_opt_group` a
|
||||
WHERE a.`id_product` = '.(int)$id_product.'
|
||||
ORDER BY a.`position` ASC';
|
||||
|
||||
if (!$res = Db::getInstance()->executeS($sql)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($res as $attribute) {
|
||||
if ((int)$attribute['id_product_configurator_opt_group'] == (int)$this->id) {
|
||||
$moved_attribute = $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($moved_attribute) || !isset($position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// < and > statements rather than BETWEEN operator
|
||||
// since BETWEEN is treated differently according to databases
|
||||
|
||||
$res1 = Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'product_configurator_opt_group`
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way
|
||||
? '> '.(int)$moved_attribute['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$moved_attribute['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_product`='.(int)$moved_attribute['id_product']
|
||||
);
|
||||
|
||||
$res2 = Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'product_configurator_opt_group`
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_product_configurator_opt_group` = '.(int)$moved_attribute['id_product_configurator_opt_group'].'
|
||||
AND `id_product`='.(int)$moved_attribute['id_product']
|
||||
);
|
||||
|
||||
return ($res1 && $res2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder attribute position in group $id_attribute_group.
|
||||
* Call it after deleting an attribute from a group.
|
||||
*
|
||||
* @param int $id_attribute_group
|
||||
* @param bool $use_last_attribute
|
||||
* @return bool $return
|
||||
*/
|
||||
public function cleanPositions($id_product, $use_last = true)
|
||||
{
|
||||
Db::getInstance()->execute('SET @i = -1', false);
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'product_configurator_opt_group` SET `position` = @i:=@i+1 WHERE';
|
||||
|
||||
if ($use_last) {
|
||||
$sql .= ' `id_product_configurator_opt_group` != '.(int)$this->id.' AND';
|
||||
}
|
||||
|
||||
$sql .= ' `id_product` = '.(int)$id_product.' ORDER BY `position` ASC';
|
||||
|
||||
$return = Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* getHigherPosition
|
||||
*
|
||||
* Get the higher position
|
||||
* Get the higher position from a group
|
||||
*
|
||||
* @param int $id_product
|
||||
* @param int $id_product_configurator_opt_group
|
||||
* @return int $position
|
||||
*/
|
||||
public static function getHigherPosition($id_product)
|
||||
public static function getHigherPosition($id_product_configurator_opt_group)
|
||||
{
|
||||
$sql = 'SELECT MAX(`position`)
|
||||
FROM `'._DB_PREFIX_.'product_configurator_opt_group`
|
||||
WHERE id_product = '.(int)$id_product;
|
||||
WHERE id_prodcut_configurator_opt_group = '.(int)$id_product_configurator_opt_group;
|
||||
|
||||
$position = DB::getInstance()->getValue($sql);
|
||||
|
||||
return (is_numeric($position)) ? $position : -1;
|
||||
}
|
||||
|
||||
}
|
@ -114,13 +114,10 @@ class AdminAntadisConfiguratorController extends ModuleAdminController
|
||||
// Row action
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('delete');
|
||||
|
||||
|
||||
self::$currentIndex = self::$currentIndex.'&id_configurator_opt_group='.(int)$id.'&viewconfigurator_opt_group';
|
||||
$this->processFilter();
|
||||
|
||||
//@todo : Re-Init all products with this option group on value change
|
||||
|
||||
|
||||
return parent::renderList();
|
||||
}
|
||||
}
|
||||
@ -477,9 +474,13 @@ class AdminAntadisConfiguratorController extends ModuleAdminController
|
||||
public function ajaxProcessUpdatePositions()
|
||||
{
|
||||
$way = (int)Tools::getValue('way');
|
||||
$id_configurator_opt = (int)Tools::getValue('id_configurator_opt');
|
||||
$id_configurator_opt_group = (int)Tools::getValue('id_configurator_opt_group');
|
||||
$id_configurator_opt = (int)Tools::getValue('id');
|
||||
$positions = Tools::getValue('configurator_opt');
|
||||
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => '"Can not update values to position"',
|
||||
);
|
||||
|
||||
if (is_array($positions)) {
|
||||
foreach ($positions as $position => $value) {
|
||||
@ -488,17 +489,25 @@ class AdminAntadisConfiguratorController extends ModuleAdminController
|
||||
if ((isset($pos[1]) && isset($pos[2])) && (int)$pos[2] === $id_configurator_opt) {
|
||||
if ($opt = new ConfiguratorOpt((int)$pos[2])) {
|
||||
if (isset($position) && $opt->updatePosition($way, $position)) {
|
||||
echo 'ok position '.(int)$position.' for values '.(int)$pos[2].'\r\n';
|
||||
echo 'ok position '.(int)$position.' for values '.(int)$pos[2]; exit;
|
||||
} else {
|
||||
echo '{"hasError" : true, "errors" : "Can not update the '.(int)$id_configurator_opt.' values to position '.(int)$position.' "}';
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => '"Can not update the '.(int)$id_configurator_opt.' values to position '.(int)$position.'"',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
echo '{"hasError" : true, "errors" : "The ('.(int)$id_configurator_opt.') values cannot be loaded"}';
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => '"The ('.(int)$id_configurator_opt.') values cannot be loaded"',
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo Tools::jsonEncode($return);
|
||||
}
|
||||
}
|
@ -1,237 +0,0 @@
|
||||
<?php
|
||||
class AdminAntadisConfiguratorProductController extends ModuleAdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->module = 'antadisconfigurator';
|
||||
$this->context = Context::getContext();
|
||||
|
||||
$this->table = 'product_configurator_opt_impact';
|
||||
$this->className = 'ProductConfiguratorOptImpact';
|
||||
$this->identifier = 'id_product_configurator_opt_impact';
|
||||
|
||||
// Enable bootstrap
|
||||
$this->bootstrap = true;
|
||||
|
||||
// Call of the parent constructor method
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Associe l'option et les valeurs au produit
|
||||
*/
|
||||
public function ajaxProcessAdd()
|
||||
{
|
||||
$id_configurator_opt_group = Tools::getValue('id_configurator_opt_group');
|
||||
$id_product = Tools::getValue('id_product');
|
||||
|
||||
// Associer OptGroup
|
||||
$result = Db::getInstance()->insert('product_configurator_opt_group', array(
|
||||
'id_product' => $id_product,
|
||||
'id_configurator_opt_group' => $id_configurator_opt_group,
|
||||
'required' => 0,
|
||||
'position' => ProductConfiguratorOptGroup::getHigherPosition($id_product) + 1,
|
||||
));
|
||||
if ($result) {
|
||||
$id_product_configurator_opt_group = Db::getInstance()->Insert_ID();
|
||||
|
||||
// Get OptGroup values
|
||||
$values = ConfiguratorOptGroup::getValues($id_configurator_opt_group);
|
||||
// Associer OptImpact
|
||||
foreach($values as $v) {
|
||||
$impact = new ProductConfiguratorOptImpact();
|
||||
$impact->id_product = $id_product;
|
||||
$impact->id_product_configurator_opt_group = $id_product_configurator_opt_group;
|
||||
$impact->id_configurator_opt = $v['id_configurator_opt'];
|
||||
$impact->price = $v['price'];
|
||||
$impact->save();
|
||||
}
|
||||
|
||||
$return = array(
|
||||
'result' => $result,
|
||||
);
|
||||
} else {
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => $this->l("Insert error : ".Db::getInstance()->getMsgError()),
|
||||
);
|
||||
}
|
||||
|
||||
echo Tools::jsonEncode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set required status
|
||||
*/
|
||||
public function ajaxProcessStatusProductConfiguratorOptGroup()
|
||||
{
|
||||
if (!$id_product_configurator_opt_group = Tools::getValue('id_product_configurator_opt_group')) {
|
||||
die(Tools::jsonEncode(array('success' => false, 'error' => 'true', 'text' => $this->l('Failed to update the required status'))));
|
||||
} else {
|
||||
$optGroup = new ProductConfiguratorOptGroup((int)$id_product_configurator_opt_group);
|
||||
if (Validate::isLoadedObject($optGroup)) {
|
||||
$optGroup->required = $optGroup->required == 1 ? 0 : 1;
|
||||
$optGroup->save() ?
|
||||
die(Tools::jsonEncode(array('success' => true, 'text' => $this->l('The required status has been updated successfully')))) :
|
||||
die(Tools::jsonEncode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the required status'))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::getIsset('deleteproduct_configurator_opt_group')) {
|
||||
$this->processDelete();
|
||||
} else {
|
||||
parent::postProcess();
|
||||
}
|
||||
}
|
||||
|
||||
public function processUpdate()
|
||||
{
|
||||
$id_product = Tools::getValue('id_product');
|
||||
$id_product_configurator_opt_group = Tools::getValue('id_product_configurator_opt_group');
|
||||
$this->redirect_after = $this->context->link->getAdminLink('AdminAntadisConfiguratorProduct').
|
||||
'&id_product='.(int)$id_product.'&id_product_configurator_opt_group='.(int)$id_product_configurator_opt_group;
|
||||
|
||||
parent::processUpdate();
|
||||
}
|
||||
|
||||
public function processDelete()
|
||||
{
|
||||
$id_product = Tools::getValue('id_product');
|
||||
$id_product_configurator_opt_group = Tools::getValue('id_product_configurator_opt_group');
|
||||
|
||||
// Supprimer les assocations group et sous éléments
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'product_configurator_opt_impact` WHERE `id_product` = '.(int)$id_product.' AND `id_product_configurator_opt_group` = '.(int)$id_product_configurator_opt_group;
|
||||
if (!$result = Db::getInstance()->execute($sql)) {
|
||||
$this->errors[] = Tools::displayError('Unable to delete items.');
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'product_configurator_opt_group` WHERE `id_product_configurator_opt_group` = '.(int)$id_product_configurator_opt_group;
|
||||
if (!Db::getInstance()->execute($sql)) {
|
||||
$this->errors[] = Tools::displayError('Unable to delete group.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirect_after = $this->context->link->getAdminLink('AdminProducts').'&id_product='.$id_product;
|
||||
}
|
||||
|
||||
public function processPosition()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdatePosition()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display impact list
|
||||
* {@inheritDoc}
|
||||
* @see AdminControllerCore::renderList()
|
||||
*/
|
||||
public function renderList()
|
||||
{
|
||||
$id_product = Tools::getValue('id_product');
|
||||
$id_product_configurator_opt_group = Tools::getValue('id_product_configurator_opt_group');
|
||||
|
||||
$optGroup = new ProductConfiguratorOptGroup($id_product_configurator_opt_group);
|
||||
|
||||
// Set fields list
|
||||
$this->fields_list = array(
|
||||
'id_product_configurator_opt_impact' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 25,
|
||||
'search' => false,
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Value'),
|
||||
'search' => false,
|
||||
),
|
||||
'price' => array(
|
||||
'title' => $this->l('Price impact'),
|
||||
'search' => false,
|
||||
'type' => 'price',
|
||||
),
|
||||
);
|
||||
|
||||
$this->_select = 'col.`name` AS name';
|
||||
$this->_join = '
|
||||
LEFT JOIN `'._DB_PREFIX_.'configurator_opt_lang` col ON (col.`id_configurator_opt` = a.`id_configurator_opt` AND col.`id_lang` = '.(int)$this->context->language->id.')';
|
||||
|
||||
$this->_where = ' AND a.`id_product` = '.(int)$id_product.' AND a.`id_product_configurator_opt_group` = '.(int)$id_product_configurator_opt_group;
|
||||
|
||||
|
||||
self::$currentIndex = self::$currentIndex.'&id_product='.$id_product;
|
||||
$this->addRowAction('edit');
|
||||
|
||||
$this->toolbar_title = Product::getProductName($id_product) . ' - ' . $optGroup->getConfiguratorOptGroupName() . ' - Options Impact';
|
||||
$this->toolbar_btn = array();
|
||||
$this->toolbar_btn['back'] = array(
|
||||
'href' => $this->context->link->getAdminLink('AdminProducts', true).'&updateproduct&id_product='.(int)$id_product,
|
||||
'desc' => $this->l('Back to product', null, null, false)
|
||||
);
|
||||
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change price impact
|
||||
* {@inheritDoc}
|
||||
* @see AdminControllerCore::renderForm()
|
||||
*/
|
||||
public function renderForm()
|
||||
{
|
||||
$id_product_configurator_opt_impact= Tools::getValue('id_product_configurator_opt_impact');
|
||||
|
||||
$optImpact = new ProductConfiguratorOptImpact($id_product_configurator_opt_impact);
|
||||
|
||||
$this->fields_form = array(
|
||||
'legend' => array('title' => $this->l('Edit price impact')),
|
||||
'input' => array(
|
||||
'id_product_configurator_opt_impact' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_product_configurator_opt_impact',
|
||||
),
|
||||
'id_product' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_product',
|
||||
),
|
||||
'id_product_configurator_opt_group' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_product_configurator_opt_group',
|
||||
),
|
||||
'id_configurator_opt' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_configurator_opt',
|
||||
),
|
||||
'price' => array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Price'),
|
||||
'hint' => $this->l('Impact de prix de l\'option'),
|
||||
'name' => 'price',
|
||||
'required' => true,
|
||||
),
|
||||
),
|
||||
'submit' => array('title' => $this->l('Save')),
|
||||
);
|
||||
|
||||
// Override cancel
|
||||
self::$currentIndex = $this->context->link->getAdminLink('AdminAntadisConfiguratorProduct', false).
|
||||
'&id_product='.$optImpact->id_product.'&id_product_configurator_opt_group='.$optImpact->id_product_configurator_opt_group;
|
||||
|
||||
$this->fields_value = array(
|
||||
'id_product_configurator_opt_impact' => $optImpact->id_product_configurator_opt_impact,
|
||||
'id_product' => $optImpact->id_product,
|
||||
'id_product_configurator_opt_group' => $optImpact->id_product_configurator_opt_group,
|
||||
'id_configurator_opt' => $optImpact->id_configurator_opt,
|
||||
'price' => $optImpact->price,
|
||||
);
|
||||
|
||||
return parent::renderForm();
|
||||
}
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
class AdminAntadisConfiguratorProductGroupController extends ModuleAdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->module = 'antadisconfigurator';
|
||||
$this->context = Context::getContext();
|
||||
|
||||
// Enable bootstrap
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->table = 'product_configurator_opt_group';
|
||||
$this->className = 'ProductConfiguratorOptGroup';
|
||||
$this->identifier = 'id_product_configurator_opt_group';
|
||||
|
||||
// Call of the parent constructor method
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::getIsset('deleteproduct_configurator_opt_group')) {
|
||||
$this->processDelete();
|
||||
} elseif (Tools::getIsset('updateproduct_configurator_opt_group')) {
|
||||
$id_product_configurator_opt_group = Tools::getValue('id_product_configurator_opt_group');
|
||||
Tools::redirectAdmin($this->context->link->getAdminLink('AdminAntadisConfiguratorProductImpact') .
|
||||
'&id_product_configurator_opt_group='.(int)$id_product_configurator_opt_group);
|
||||
} else {
|
||||
parent::postProcess();
|
||||
}
|
||||
}
|
||||
|
||||
public function processDelete()
|
||||
{
|
||||
$id_product_configurator_opt_group = Tools::getValue('id_product_configurator_opt_group');
|
||||
$id_product = Tools::getValue('id_product');
|
||||
if ($id_product === null) {
|
||||
$this->errors[] = Tools::displayError('Error id_product is missing.');
|
||||
} else {
|
||||
// Delete impact
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'product_configurator_opt_impact` WHERE `id_product_configurator_opt_group` = '.(int)$id_product_configurator_opt_group;
|
||||
if (!$result = Db::getInstance()->execute($sql)) {
|
||||
$this->errors[] = Tools::displayError('Unable to delete items.');
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
// Delete group associated
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'product_configurator_opt_group` WHERE `id_product_configurator_opt_group` = '.(int)$id_product_configurator_opt_group;
|
||||
if (!Db::getInstance()->execute($sql)) {
|
||||
$this->errors[] = Tools::displayError('Unable to delete group.');
|
||||
}
|
||||
|
||||
// Re-order
|
||||
$obj = new ProductConfiguratorOptGroup();
|
||||
$obj->cleanPositions($id_product);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
// Get Product for reference
|
||||
$id_product = (int)Tools::getValue('id_product');
|
||||
|
||||
// Override page title
|
||||
$this->page_header_toolbar_title = 'Product Options : ' . Product::getProductName($id_product);
|
||||
|
||||
//Add back button to product
|
||||
$this->toolbar_btn = array();
|
||||
$this->toolbar_btn['back'] = array(
|
||||
'href' => $this->context->link->getAdminLink('AdminProducts').'&updateproduct&id_product='.(int)$id_product,
|
||||
'desc' => $this->l('Back to product', null, null, false)
|
||||
);
|
||||
|
||||
// Position
|
||||
$this->position_identifier = 'id_product_configurator_opt_group';
|
||||
|
||||
// Remove filters
|
||||
$this->list_simple_header = true;
|
||||
|
||||
// List
|
||||
$this->fields_list = array(
|
||||
'id_product_configurator_opt_group' => array(
|
||||
'title' => $this->l('ID')
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Option Name'),
|
||||
),
|
||||
'required' => array(
|
||||
'title' => $this->l('Required'),
|
||||
'active' => 'status',
|
||||
'type' => 'bool',
|
||||
'ajax' => true,
|
||||
),
|
||||
'position' => array(
|
||||
'title' => $this->l('Position'),
|
||||
'position' => 'position',
|
||||
'class' => 'fixed-width-md'
|
||||
),
|
||||
);
|
||||
|
||||
// Override SQL to get name
|
||||
$this->_select = ' cogl.`name`';
|
||||
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'configurator_opt_group_lang` cogl ON(cogl.`id_configurator_opt_group` = a.`id_configurator_opt_group`)';
|
||||
$this->_where = ' AND a.`id_product` = '.(int)$id_product;
|
||||
$this->_orderBy = 'position';
|
||||
|
||||
// Only delete action
|
||||
$this->addRowAction('delete');
|
||||
|
||||
self::$currentIndex = self::$currentIndex.'&id_product='.(int)$id_product;
|
||||
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate option and his items to product
|
||||
*/
|
||||
public function ajaxProcessAdd()
|
||||
{
|
||||
$id_configurator_opt_group = Tools::getValue('id_configurator_opt_group');
|
||||
$id_product = Tools::getValue('id_product');
|
||||
|
||||
// Associer OptGroup
|
||||
$result = Db::getInstance()->insert('product_configurator_opt_group', array(
|
||||
'id_product' => $id_product,
|
||||
'id_configurator_opt_group' => $id_configurator_opt_group,
|
||||
'required' => 0,
|
||||
'position' => ProductConfiguratorOptGroup::getHigherPosition($id_product) + 1,
|
||||
));
|
||||
if ($result) {
|
||||
$id_product_configurator_opt_group = Db::getInstance()->Insert_ID();
|
||||
|
||||
// Get OptGroup values
|
||||
$values = ConfiguratorOptGroup::getValues($id_configurator_opt_group);
|
||||
// Associer OptImpact
|
||||
foreach($values as $v) {
|
||||
$impact = new ProductConfiguratorOptImpact();
|
||||
$impact->id_product = $id_product;
|
||||
$impact->id_product_configurator_opt_group = $id_product_configurator_opt_group;
|
||||
$impact->id_configurator_opt = $v['id_configurator_opt'];
|
||||
$impact->price = $v['price'];
|
||||
$impact->save();
|
||||
}
|
||||
|
||||
$return = array(
|
||||
'result' => $result,
|
||||
);
|
||||
} else {
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => $this->l("Insert error : ".Db::getInstance()->getMsgError()),
|
||||
);
|
||||
}
|
||||
|
||||
echo Tools::jsonEncode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set required status
|
||||
*/
|
||||
public function ajaxProcessStatusProductConfiguratorOptGroup()
|
||||
{
|
||||
if (!$id_product_configurator_opt_group = Tools::getValue('id_product_configurator_opt_group')) {
|
||||
die(Tools::jsonEncode(array('success' => false, 'error' => 'true', 'text' => $this->l('Failed to update the required status'))));
|
||||
} else {
|
||||
$optGroup = new ProductConfiguratorOptGroup((int)$id_product_configurator_opt_group);
|
||||
if (Validate::isLoadedObject($optGroup)) {
|
||||
$optGroup->required = $optGroup->required == 1 ? 0 : 1;
|
||||
$optGroup->save() ?
|
||||
die(Tools::jsonEncode(array('success' => true, 'text' => $this->l('The required status has been updated successfully')))) :
|
||||
die(Tools::jsonEncode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the required status'))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify position
|
||||
*/
|
||||
public function ajaxProcessUpdatePositions()
|
||||
{
|
||||
$way = (int)Tools::getValue('way');
|
||||
$id = (int)Tools::getValue('id');
|
||||
$positions = Tools::getValue('product_configurator_opt_group');
|
||||
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => 'Can not update values to position',
|
||||
);
|
||||
|
||||
if (is_array($positions)) {
|
||||
foreach ($positions as $position => $value) {
|
||||
$pos = explode('_', $value);
|
||||
|
||||
if ((isset($pos[1]) && isset($pos[2])) && (int)$pos[2] === $id) {
|
||||
if ($opt = new ProductConfiguratorOptGroup((int)$pos[2])) {
|
||||
if (isset($position) && $opt->updatePosition($way, $position)) {
|
||||
echo 'ok position '.(int)$position.' for values '.(int)$pos[2];
|
||||
exit;
|
||||
} else {
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => 'Can not update the '.(int)$id.' values to position '.(int)$position,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => 'The ('.(int)$id.') values cannot be loaded',
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
die(Tools::jsonEncode($return));
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
class AdminAntadisConfiguratorProductImpactController extends ModuleAdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->module = 'antadisconfigurator';
|
||||
$this->context = Context::getContext();
|
||||
|
||||
// Enable bootstrap
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->table = 'product_configurator_opt_impact';
|
||||
$this->className = 'ProductConfiguratorOptImpact';
|
||||
$this->identifier = 'id_product_configurator_opt_impact';
|
||||
|
||||
// Call of the parent constructor method
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function processUpdate()
|
||||
{
|
||||
$id_product = Tools::getValue('id_product');
|
||||
$id_product_configurator_opt_group = Tools::getValue('id_product_configurator_opt_group');
|
||||
$this->redirect_after = $this->context->link->getAdminLink('AdminAntadisConfiguratorProductImpact').
|
||||
'&id_product='.(int)$id_product.'&id_product_configurator_opt_group='.(int)$id_product_configurator_opt_group;
|
||||
parent::processUpdate();
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
// Get Product for reference
|
||||
$id_product_configurator_opt_group = (int)Tools::getValue('id_product_configurator_opt_group');
|
||||
|
||||
$objectGroup = new ProductConfiguratorOptGroup($id_product_configurator_opt_group);
|
||||
$id_product = $objectGroup->id_product;
|
||||
|
||||
// Override page title
|
||||
$this->page_header_toolbar_title = 'Product Options Impact : ' . Product::getProductName($id_product);
|
||||
|
||||
//Add back button to product
|
||||
$this->toolbar_btn = array();
|
||||
$this->toolbar_btn['back'] = array(
|
||||
'href' => $this->context->link->getAdminLink('AdminProducts').'&updateproduct&id_product='.(int)$id_product,
|
||||
'desc' => $this->l('Back to product', null, null, false)
|
||||
);
|
||||
$this->toolbar_btn['backGroup'] = array(
|
||||
'href' => $this->context->link->getAdminLink('AdminAntadisConfiguratorProductGroup').'&id_product_configurator_opt_group='.(int)$id_product_configurator_opt_group,
|
||||
'desc' => $this->l('Back to group', null, null, false)
|
||||
);
|
||||
|
||||
// Remove filters
|
||||
$this->list_simple_header = true;
|
||||
|
||||
// Set fields list
|
||||
$this->fields_list = array(
|
||||
'id_product_configurator_opt_impact' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 25,
|
||||
'search' => false,
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Value'),
|
||||
'search' => false,
|
||||
),
|
||||
'price' => array(
|
||||
'title' => $this->l('Price impact'),
|
||||
'search' => false,
|
||||
'type' => 'price',
|
||||
),
|
||||
);
|
||||
|
||||
$this->_select = 'col.`name` AS name';
|
||||
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'configurator_opt_lang` col
|
||||
ON (col.`id_configurator_opt` = a.`id_configurator_opt` AND col.`id_lang` = '.(int)$this->context->language->id.')';
|
||||
$this->_where = ' AND a.`id_product` = '.(int)$id_product.' AND a.`id_product_configurator_opt_group` = '.(int)$id_product_configurator_opt_group;
|
||||
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$id_product_configurator_opt_impact = Tools::getValue('id_product_configurator_opt_impact');
|
||||
|
||||
$optImpact = new ProductConfiguratorOptImpact($id_product_configurator_opt_impact);
|
||||
|
||||
// Override page title
|
||||
$this->page_header_toolbar_title = 'Product Options Impact :' . Product::getProductName($optImpact->id_product);
|
||||
|
||||
// Override cancel
|
||||
self::$currentIndex = self::$currentIndex.'&id_product='.$optImpact->id_product.'&id_product_configurator_opt_group='.$optImpact->id_product_configurator_opt_group;
|
||||
|
||||
$this->fields_form = array(
|
||||
'legend' => array('title' => $this->l('Edit price impact')),
|
||||
'input' => array(
|
||||
'id_product_configurator_opt_impact' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_product_configurator_opt_impact',
|
||||
),
|
||||
'id_product' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_product',
|
||||
),
|
||||
'id_product_configurator_opt_group' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_product_configurator_opt_group',
|
||||
),
|
||||
'id_configurator_opt' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_configurator_opt',
|
||||
),
|
||||
'price' => array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Price'),
|
||||
'hint' => $this->l('Impact de prix de l\'option'),
|
||||
'name' => 'price',
|
||||
'required' => true,
|
||||
),
|
||||
),
|
||||
'submit' => array('title' => $this->l('Save')),
|
||||
);
|
||||
|
||||
$this->fields_value = array(
|
||||
'id_product_configurator_opt_impact' => $optImpact->id_product_configurator_opt_impact,
|
||||
'id_product' => $optImpact->id_product,
|
||||
'id_product_configurator_opt_group' => $optImpact->id_product_configurator_opt_group,
|
||||
'id_configurator_opt' => $optImpact->id_configurator_opt,
|
||||
'price' => $optImpact->price,
|
||||
);
|
||||
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
}
|
@ -41,8 +41,6 @@ class AntadisConfiguratorDisplayAdminProductsExtraController
|
||||
),
|
||||
'position' => array(
|
||||
'title' => $this->module->l('Position'),
|
||||
'filter_key' => 'a!position',
|
||||
'position' => 'position',
|
||||
'class' => 'fixed-width-md'
|
||||
),
|
||||
);
|
||||
@ -60,10 +58,11 @@ class AntadisConfiguratorDisplayAdminProductsExtraController
|
||||
$helper->position_identifier = 'id_product_configurator_opt_group';
|
||||
$helper->orderBy = 'position';
|
||||
|
||||
$helper->actions = array('delete');
|
||||
$helper->no_link = true;
|
||||
|
||||
$helper->token = Tools::getAdminTokenLite('AdminAntadisConfiguratorProduct');
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminAntadisConfiguratorProduct', false).'&id_product='.(int)$id_product;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminAntadisConfiguratorProductGroup');
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminAntadisConfiguratorProductGroup', false).
|
||||
'&id_product='.(int)$id_product;
|
||||
|
||||
// Available options
|
||||
$optGroupList = ConfiguratorOptGroup::getAll();
|
||||
@ -74,6 +73,7 @@ class AntadisConfiguratorDisplayAdminProductsExtraController
|
||||
'OptGroupList' => $optGroupList,
|
||||
'OptGroupListFormLink' => $this->context->link->getAdminLink('AdminProducts').'&id_product='.(int)$id_product,
|
||||
'ProductOptGroupList' => $helper->generateList($productOptGroupList, $fields_list),
|
||||
'ConfigureLink' => $this->context->link->getAdminLink('AdminAntadisConfiguratorProductGroup').'&id_product='.(int)$id_product,
|
||||
));
|
||||
|
||||
return $this->module->display($this->file, 'displayAdminProductsExtra.tpl');
|
||||
|
@ -29,7 +29,7 @@ CREATE TABLE `ps_configurator_opt_lang` (
|
||||
`id_lang` int(11) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id_configurator_opt`,`id_lang`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
||||
|
||||
|
||||
CREATE TABLE `ps_configurator_storage` (
|
||||
|
@ -1,5 +0,0 @@
|
||||
<?php
|
||||
class AdminOrdersController extends AdminController
|
||||
{
|
||||
|
||||
}
|
@ -2,8 +2,13 @@
|
||||
<div id="product-configurator-opt" class="panel product-tab">
|
||||
<div class="panel-heading">{l s='Add options for this product'}</div>
|
||||
<div class="panel-body">
|
||||
<form id="product-configurator-opt-add" name="product-configurator-opt-add" class="form-inline" method="post" data-token="{$token}" action="{$OptGroupListFormLink}">
|
||||
<input type="hidden" name="id_product" value="{$id_product}"/>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<a href="{$ConfigureLink}" class="btn btn-default">{l s='Configure associated options'}</a>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<form id="product-configurator-opt-add" name="product-configurator-opt-add" class="form-inline" method="post" data-token="{$token}" action="{$OptGroupListFormLink}">
|
||||
<input type="hidden" name="id_product" value="{$id_product}"/>
|
||||
<div class="form-group">
|
||||
<select name="id_configurator_opt_group" class="form-control">
|
||||
<option value="">-</option>
|
||||
@ -12,8 +17,10 @@
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default pull-right">{l s="Add New option"}</button>
|
||||
</form>
|
||||
<button type="submit" class="btn btn-default">{l s="Add New option"}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
@ -22,7 +29,7 @@ $('form#product-configurator-opt-add').submit(function(){
|
||||
var postData = {
|
||||
//required parameters
|
||||
ajax : true,
|
||||
controller : 'AdminAntadisConfiguratorProduct',
|
||||
controller : 'AdminAntadisConfiguratorProductGroup',
|
||||
action : 'Add',
|
||||
token : $(this).attr('data-token'),
|
||||
//additional parameters to your controller
|
||||
@ -42,6 +49,5 @@ $('form#product-configurator-opt-add').submit(function(){
|
||||
});
|
||||
</script>
|
||||
|
||||
{*Gestion des OptGroup*}
|
||||
{$ProductOptGroupList}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user