我想知道如何在模塊頁面複選框可以進行檢查 我的代碼是: -的Prestashop複選框檢查
if (!defined('_PS_VERSION_')) {
exit;
}
class ExportOrders extends Module
{
protected $config_form = false;
protected $_html = '';
protected $_postErrors = array();
public function __construct()
{
$this->name = 'exportorders';
$this->tab = 'export';
$this->version = '1.0.1';
$this->author = 'Decathlon Sports India Limited';
$this->need_instance = 1;
/**
* Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
*/
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('ExportOrders');
$this->description = $this->l('generating xml for exportorder based on manual and automation process');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall the module');
}
/**
* Don't forget to create update methods if needed:
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
*/
public function install()
{
if (!parent::install() OR ! $this->alterTable('add') OR ! $this->registerHook('actionAdminControllerSetMedia') OR ! $this->registerHook('actionProductUpdate') OR ! $this->registerHook('displayAdminProductsExtra'))
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall() OR ! $this->alterTable('remove'))
return false;
return true;
}
public function alterTable($method)
{
switch ($method) {
case 'add':
$sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'order_history ADD `export_orders` int NOT NULL';
break;
case 'remove':
$sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'order_history DROP COLUMN `export_orders`';
break;
}
if (!Db::getInstance()->Execute($sql))
return false;
return true;
}
/**
* Load the configuration form
*/
public function prepareNewTab()
{
$this->context->smarty->assign(array(
'custom_field' => '',
'languages' => $this->context->controller->_languages,
'default_language' => (int)Configuration::get('PS_LANG_DEFAULT')
));
}
/**
* Validating the settings form
*/
protected function _postValidation()
{
if (Tools::isSubmit('submitexportordersModule'))
{
// if (!Tools::getValue('Order Id'))
// $this->_postErrors[] = $this->l('Order Id is mandatory.');
if (!Tools::getValue('EXPORTORDERS_LOCATION'))
$this->_postErrors[] = $this->l('Export Location is required.');
}
}
public function getContent()
{
/**
* If values have been submitted in the form, process.
*/
if (((bool)Tools::isSubmit('submitexportordersModule')) == true){
$this->_postValidation();
if (!count($this->_postErrors))
$this->postProcess();
else
foreach ($this->_postErrors as $err)
$this->_html .= $this->displayError($err);
}
else
$this->_html .= '<br />';
$this->_html .= $this->renderForm();
return $this->_html;
$this->context->smarty->assign('module_dir', $this->_path);
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
return $output.$this->renderForm();
}
/**
* Create the form that will be displayed in the configuration of your module.
*/
protected function renderForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitexportordersModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
$helper->fields_value[OrderID] = true;
return $helper->generateForm(array($this->getConfigForm()));
}
/**
* Create the structure of your form.
*/
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'checkbox',
'label' => $this->l('Select Required Options'),
// 'required' => true,
'values' => array(
'query' => array(
array(
'id' => 'AllFields',
'name' => $this->l('All Fields'),
'val' => 'All',
'class' => 'check_all',
),
array(
'id' => 'OrderID',
'name' => $this->l('Order Id'),
'val' => 1,
'required' => true,
'class' => 'order_id',
), array(
'id' => 'InvoiceNo',
'name' => $this->l('Invoice No'),
'val' => 1,
), array(
'id' => 'ShippedDate',
'name' => $this->l('Shipped Date'),
'val' => 1,
), array(
'id' => 'PaymentMethod',
'name' => $this->l('Payment Method'),
'val' => 1,
), array(
'id' => 'TransportCost',
'name' => $this->l('Transport Cost'),
'val' => 1,
), array(
'id' => 'OrderStatus',
'name' => $this->l('Order Status'),
'val' => 1,
), array(
'id' => 'MyDecathlonId',
'name' => $this->l('Decathlon Id'),
'val' => 1,
), array(
'id' => 'FirstName',
'name' => $this->l('First Name'),
'val' => 1,
), array(
'id' => 'LastName',
'name' => $this->l('Last Name'),
'val' => 1,
), array(
'id' => 'Address1',
'name' => $this->l('Address1'),
'val' => 1,
), array(
'id' => 'Address2',
'name' => $this->l('Address2'),
'val' => 1,
'id' => 'State',
'name' => $this->l(' State'),
'val' =>1,
), array(
'id' => 'ZipCode',
'name' => $this->l(' ZipCode'),
'val' =>1,
), array(
'id' => 'Phone',
'name' => $this->l('Phone'),
'val' => 1,
), array(
'id' => 'Email',
'name' => $this->l('Email'),
'val' => 1,
), array(
'id' => 'Item',
'name' => $this->l('Item'),
'val' => 1,
), array(
'id' => 'QuantityOrdered',
'name' => $this->l('Quantity Ordered'),
'val' => 1,
), array(
'id' => 'QuantityReturned',
'name' => $this->l('Quantity Returned'),
'val' => 1,
), array(
'id' => 'GrossAmount',
'name' => $this->l('Gross Amount'),
'val' => 1,
), array(
'id' => 'NetAmount',
'name' => $this->l('Net Amount'),
'val' => 1,
), array(
'id' => 'TaxRate',
'name' => $this->l('Tax Rate'),
'val' => 1,
), array(
'id' => 'Currency',
'name' => $this->l('Currency'),
'val' => 1,
),
),
'id' => 'id',
'name' => 'name'
),
),
array(
'type' => 'text',
'name' => 'EXPORTORDERS_LOCATION',
'label' => $this->l('Export Location'),
'required' => true
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}
/**
* Set values for the inputs.
*/
protected function getConfigFormValues()
{
return array(
'EXPORTORDERS_LOCATION' => Configuration::get('EXPORTORDERS_LOCATION'),
);
}
/**
* Save form data.
*/
protected function postProcess()
{
//Initialise arrays and values
$form_values = $this->getConfigFormValues();
$_POST['module_name'] = 'export_orders';
$arr = array_map('utf8_encode', $_POST);
$test = json_encode($arr);
$insertData = array(
'name' => $_POST['module_name'],
'date_add' => date('Y-m-d H:i:s'),
'value' => $test
);
$updateData = array(
'date_upd' => date('Y-m-d H:i:s'),
'value' => $test
);
//Fetch from configuration table
$sql = 'SELECT * FROM '._DB_PREFIX_.'configuration WHERE name = "export_orders"';
if ($row = Db::getInstance()->getRow($sql))
$decoded_values = json_decode($row['value']);
if($decoded_values == ""){
Db::getInstance()->insert("configuration", $insertData);
}
else
Db::getInstance()->update('configuration', $updateData, 'name = "export_orders"');
foreach (array_keys($form_values) as $key) {
// Configuration::updateValue($key, Tools::getValue($key));
}
}
/**
* Add the CSS & JavaScript files you want to be loaded in the BO.
*/
public function hookBackOfficeHeader()
{
if (Tools::getValue('module_name') == $this->name) {
$this->context->controller->addJS($this->_path.'views/js/back.js');
$this->context->controller->addJS($this->_path.'views/js/back_checkall.js');
$this->context->controller->addCSS($this->_path.'views/css/back.css');
}
}
/**
* Add the CSS & JavaScript files you want to be added on the FO.
*/
public function hookHeader()
{
$this->context->controller->addJS($this->_path.'/views/js/front.js');
$this->context->controller->addCSS($this->_path.'/views/css/front.css');
}
public function hookDisplayBackOfficeHeader()
{
/* Place your code here. */
}
public function hookDisplayBackOfficeHome()
{
/* Place your code here. */
}
}
也想知道我怎麼可以讓全選來選擇所有的複選框。我已經試過很多着成功,請大家幫我
我曾試圖複選框被選中,但沒有得到正確的
我有絕對的Prestashop沒有經驗,但由於這只是一個PHP關聯數組:你嘗試過'=> TRUE'而不是「檢查」'檢查「(因爲這不是一個布爾值)? – indextwo
#indextwo不,不適用 –