Witam serdecznie.
Zduplikowałem moduł odpowiedzialny za wybieranie przy zamówieniu czy klient chce paragon i fakturę. Chciałem go zduplikować jako osobny moduł aby dodać jeszcze opcję wyboru Wniosku NFZ. Co zrobiłem aby zduplikować moduł:
- Dodałem "2" do nazwy folderu oraz wszystkich plików które znajdują się w katalogu modułu (nie wliczając katalogów).
- Wydedytowałem odpowiednio wszystkie pliki zduplikowanego stylu np. główny plik php:
<?php
if (!defined('_PS_VERSION_'))
exit;
class twParagonFaktura2 extends Module {
const _PARAGON_FAKTURA2_ = 'tw_paragonfaktura2';
public static $documentType2 = array();
public function __construct() {
$this->name = 'twparagonfaktura2';
$this->tab = 'billing_invoicing'; // front_office_features'; //
$this->version = '1.0';
$this->author = 'Tomek Witek';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
self::$documentType = array('Yes' => $this->l('Yes'),
'No' => $this->l('No')
);
$this->displayName = $this->l('Receipt or invoice?');
$this->description = $this->l('The module allows you to choose the type of document confirming the purchase of goods (receipt or invoice)');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
} // ------------------------------------------------------------------------------------------------- __construct()
public function addOverride($classname) {
if ( version_compare(_PS_VERSION_, '1.6.1.0', '<') ) {
return parent::addOverride($classname);
} else {
return true;
}
} // ------------------------------------------------------------------------------------------------- addOverride()
public function install() {
reset(self::$documentType);
$sql = 'CREATE TABLE IF NOT EXISTS`'._DB_PREFIX_.self::_PARAGON_FAKTURA2_.'` (
`id_cart` int(11) NOT NULL,
`document_type` ENUM(\''.implode("','", array_keys(self::$documentType) ).'\') NOT NULL DEFAULT \''.key(self::$documentType).'\',
PRIMARY KEY(`id_cart`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;';
return( parent::install() &&
$this->registerHook('displayShoppingCartFooter') &&
$this->registerHook('displayReceiptInvoiceExtra') &&
$this->registerHook('displayOrderDetail') &&
$this->registerHook('displayAdminOrder') &&
$this->registerHook('displayAdminOrderExtra') &&
$this->registerHook('actionGetExtraMailTemplateVars') &&
Configuration::updateValue('TW_PARAGON_FAKTURA2', key(self::$documentType)) &&
Db::getInstance()->execute($sql)
);
} // ------------------------------------------------------------------------------------------------- install()
public function removeOverride($classname) {
if ( version_compare(_PS_VERSION_, '1.6.1.0', '<') ) {
return parent::removeOverride($classname);
} else {
return true;
}
} // ------------------------------------------------------------------------------------------------- removeOverride()
public function uninstall() {
$sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.self::_PARAGON_FAKTURA2_.'`;';
return( parent::uninstall() &&
$this->unregisterHook('displayShoppingCartFooter') &&
$this->unregisterHook('displayReceiptInvoiceExtra') &&
$this->unregisterHook('displayOrderDetail') &&
$this->unregisterHook('displayAdminOrder') &&
$this->unregisterHook('displayAdminOrderExtra') &&
$this->unregisterHook('actionGetExtraMailTemplateVars') &&
Configuration::deleteByName('TW_PARAGON_FAKTURA2') &&
Db::getInstance()->execute($sql)
);
} // ------------------------------------------------------------------------------------------------- uninstall()
public function getContent() {
if (Tools::isSubmit('submitSaveConfiguration')) {
Configuration::updateValue('TW_PARAGON_FAKTURA2', Tools::getValue('TW_PARAGON_FAKTURA2'));
}
return $this->renderConfigForm();
} // ------------------------------------------------------------------------------------------------- getContent()
public function renderConfigForm() {
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Configuration'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'select',
'label' => $this->l('Default document'),
'name' => 'TW_PARAGON_FAKTURA2',
'desc' => $this->l('Set the default document confirming the purchase of goods'),
'options' => array(
'query' => $this->getDocumentTypes(),
'id' => 'id_option',
'name' => 'name'
),
),
),
'submit' => array(
'title' => $this->l('Save'),
)
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->name;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->module = $this;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitSaveConfiguration';
$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' => array(
'TW_PARAGON_FAKTURA2' => Tools::getValue('TW_PARAGON_FAKTURA2', Configuration::get('TW_PARAGON_FAKTURA2')),
),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form));
} // --------------------------------------------------------------------------------------------------------- _renderConfigForm()
public function getDocumentTypes() {
$options = array();
foreach( self::$documentType as $docType => $docName ) {
$options[] = array( 'id_option' => $docType, 'name' => $docName );
}
return $options;
} // --------------------------------------------------------------------------------------------------------- getDocumentTypes()
public function getCurrentDocumentType($id_cart) {
$sql = 'SELECT `document_type` FROM `'._DB_PREFIX_.self::_PARAGON_FAKTURA2_.'` WHERE `id_cart`='.$id_cart.';';
$currentDocument = Db::getInstance()->getValue($sql);
return ( array_key_exists($currentDocument, self::$documentType) ? $currentDocument : 'unknow' );
} // --------------------------------------------------------------------------------------------------------- getCurrentDocumentType()
public function getCurrentDocumentName($currentDocument, $unknow = 'unknow' ) {
return ( array_key_exists($currentDocument, self::$documentType) ? self::$documentType[$currentDocument] : $unknow );
} // --------------------------------------------------------------------------------------------------------- getCurrentDocumentName()
public function _prepareHook() {
$this->context->controller->addCSS(($this->_path).'views/css/twparagonfaktura2.css', 'all');
$this->context->controller->addJS(($this->_path).'views/js/twparagonfaktura2.js');
// --------------------------- dodaje rekord jezeli nie istnieje (z domyslnym typem dokumentu - klient nie wybral rodzaju dokumentu)
// --------------------------- dla danego koszyka (id_cart) zostanie wykonane tylko JEDEN RAZ!
$sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.self::_PARAGON_FAKTURA2_.'`
(`id_cart`, `document_type`)
VALUES ('.$this->context->cart->id.', "'.Configuration::get('TW_PARAGON_FAKTURA2').'" )';
Db::getInstance()->execute($sql);
// --------------------------- odczytuje biezacy typ dokumentu, typ dokumentu moze byc inny niz po dodaniu rekordu
// --------------------------- np po ponownym wejscu do koszyka - klient wczesniej zmienil typ dokumentu,
// --------------------------- zobacz paragonfaktuta2.js, ajax2.php
$currentDocument = $this->getCurrentDocumentType($this->context->cart->id);
$this->smarty->assign(array(
'documentType' => self::$documentType,
'currentDocument' => $currentDocument,
'id_cart' => $this->context->cart->id,
));
} // --------------------------------------------------------------------------------------------------------- _prepareHook()
public function hookdisplayReceiptInvoiceExtra($params) {
$this->_prepareHook();
return $this->display(__FILE__, 'views/templates/hook/paragonfaktura2.tpl');
} // --------------------------------------------------------------------------------------------------------- hookdisplayReceiptInvoiceExtra()
public function hookDisplayShoppingCartFooter($params){
$this->_prepareHook();
return $this->display(__FILE__, 'views/templates/hook/paragonfaktura2.tpl');
} // --------------------------------------------------------------------------------------------------------- hookDisplayShoppingCartFooter()
public function hookDisplayOrderDetail($params) {
$currentDocument = $this->getCurrentDocumentType($params['order']->id_cart);
if ($currentDocument == 'unknow')
return false;
$this->smarty->assign(array(
'currentDocument' => $currentDocument,
'currentDocumentTranslate' => $this->getCurrentDocumentName($currentDocument),
));
return $this->display(__FILE__, 'views/templates/hook/order_detail2.tpl');
} // --------------------------------------------------------------------------------------------------------- hookDisplayOrderDetail()
public function _prepareAdminHook() {
$currentDocument = $this->getCurrentDocumentType($this->context->cart->id);
$this->smarty->assign(array(
'currentDocument' => $currentDocument,
'currentDocumentTranslate' => $this->getCurrentDocumentName($currentDocument),
));
} // --------------------------------------------------------------------------------------------------------- _prepareAdminHook()
public function hookDisplayAdminOrder($params) {
$this->_prepareAdminHook();
return $this->display(__FILE__, 'views/templates/admin/admin_orders2.tpl');
} // ---------------------------------------------------------------------------------------------------------- hookDisplayAdminOrder()
public function hookDisplayAdminOrderExtra($params) {
$this->_prepareAdminHook();
return $this->display(__FILE__, 'views/templates/admin/admin_orders2.tpl');
} // ---------------------------------------------------------------------------------------------------------- hookDisplayAdminOrderExtra()
public function hookActionGetExtraMailTemplateVars($params) {
if ($params['template'] == 'order_conf' || $params['template'] == 'new_order') {
$currentDocument = $this->getCurrentDocumentType($this->context->cart->id);
$params['extra_template_vars']['{receipt_invoice}'] = $this->getCurrentDocumentName($currentDocument, '');
}
} // ---------------------------------------------------------------------------------------------------------- hookActionGetExtraMailTemplateVars()
}
Wszytko na pierwszy rzut oka powinno działać jednak gdy wybieram przy zamówieniu 1 pole (Paragon czy Faktura) to pod zarówno 1 jak i 2 polem na raz wyświetlają się błędy o uaktualnieniu i błędzie co skutkuje tym że 2 pole nie zmienia się po zakończeniu zamówienia (pozostaje domyslne - takie jakie jest ustawione w opcjach modułu) W bazie danych SQL tak samo widnieje tylko opcja domyślna, nie zmieniona.
Gdzie robię błąd ?