✏️ 正在编辑: AdminEcPriceTextController.php
路径:
/home/bpioifn/www/pigmentse/modules/easycart/controllers/admin/AdminEcPriceTextController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * Please do not edit or add any code in this file without the permission of PIBBLU * * @author Saravana Technology Solutions * @copyright Saravana Technology Solutions * @license http://www.pibblu.in * Prestashop version 1.7+ * easycart 1.0.0 * Dec 2017 */ require_once(_PS_MODULE_DIR_.'easycart/classes/ecpricetext.php'); class AdminEcPriceTextController extends ModuleAdminController { public function __construct() { $this->addRowAction('edit'); $this->addRowAction('delete'); $this->explicitSelect = false; $this->context = Context::getContext(); $this->id_lang = $this->context->language->id; $this->lang = true; $this->ajax = 1; $this->path = _MODULE_DIR_.'easycart'; $this->default_form_language = $this->context->language->id; $this->table = 'ecpricetext'; $this->className = 'Ecpricetext'; $this->identifier = 'id_ecpricetext'; $this->allow_export = true; $this->name = 'AdminEcPriceTextController'; $this->bootstrap = true; parent::__construct(); $this->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected items only'), 'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?') ), 'deleteallrecords' => array( 'text' => $this->l('Delete ALL items [Items cannot be restored]'), 'icon' => 'icon-trash text-danger', 'confirm' => $this->l('Delete All records? You cannot restore them back!') ), ); $this->fields_list = array( 'id_product' => array('title' => $this->l('Product Id'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'product_name' => array('title' => $this->l('Product Name'), 'align' => 'center', 'class' => 'fixed-width-xl'), 'id_shop' => array('title' => $this->l('Shop ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'pricetext' => array('title' => $this->l('Price Text'), 'filter_key' => 'b!pricetext', 'align' => 'center', 'class' => 'fixed-width-xs'), ); } protected function processBulkDeleteallrecords() { $object = new $this->className(); return $object->deleteAllRecords(); } public function initPageHeaderToolbar() { $this->page_header_toolbar_title = $this->l('Price Text'); parent::initPageHeaderToolbar(); } public function initToolbar() { parent::initToolbar(); $this->context->smarty->assign('toolbar_scroll', 1); $this->context->smarty->assign('show_toolbar', 1); $this->context->smarty->assign('toolbar_btn', $this->toolbar_btn); } public function postProcess() { if ($this->display == 'edit' || $this->display == 'add') { $this->addJS($this->path.'/views/js/product_rule.js', 'all'); $this->addJqueryUI(array( 'ui.core', 'ui.widget' )); $this->addjQueryPlugin(array( 'autocomplete', 'fancybox', 'typewatch', 'tablednd', 'thickbox', 'ajaxfileupload', 'date', 'tagify', 'select2', 'validate' )); $this->addJS(array( _PS_JS_DIR_.'tiny_mce/tiny_mce.js', _PS_JS_DIR_.'admin/tinymce.inc.js', _PS_JS_DIR_.'admin/dnd.js', _PS_JS_DIR_.'jquery/ui/jquery.ui.progressbar.min.js', _PS_JS_DIR_.'vendor/spin.js', _PS_JS_DIR_.'vendor/ladda.js' )); $this->addJS(_PS_JS_DIR_.'jquery/plugins/select2/select2_locale_'.$this->context->language->iso_code.'.js'); $this->addJS(_PS_JS_DIR_.'jquery/plugins/validate/localization/messages_'.$this->context->language->iso_code.'.js'); $this->addJS($this->path.'/views/js/bo.js', 'all'); $this->addCSS(array( _PS_JS_DIR_.'jquery/plugins/timepicker/jquery-ui-timepicker-addon.css', _PS_BO_ALL_THEMES_DIR_.$this->bo_theme.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.$this->bo_css, )); } if (Tools::getIsset('ajax_product_list')) { $this->processAjaxProductsList(); } parent::postProcess(); } public function renderView() { return $this->renderForm(); } public function renderForm() { //$defaultweight = Configuration::get('PS_WEIGHT_UNIT'); //$currency = new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT')); //$defaultcurrencyname = $currency->name; //$defaultcurrencysign = $currency->sign; $this->fields_form = array( 'legend' => array( 'title' => $this->l('Price Text'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'hidden', 'label' => $this->l('Product Id:'), 'name' => 'id_product', 'id' => 'id_product', 'required' => true, 'hint' => $this->l('Enter Product ID. Do not enter special characters:'), ), array( 'type' => 'hidden', 'label' => $this->l('Product Name:'), 'name' => 'product_name', 'id' => 'product_name', 'required' => false, ), array( 'type' => 'shop', 'label' => $this->l('Shop:'), 'name' => 'id_shop', ), array( 'type' => 'text', 'lang' => true, 'label' => $this->l('Price Text'), 'name' => 'pricetext', 'class' => 'col-lg-2',), ), 'submit' => array( 'title' => $this->l('Save'), ) ); if (!($obj = $this->loadObject(true))) { return; } foreach ($this->fields_form['input'] as $inputfield) { if ($inputfield['name'] === 'pricetext') { $info = new Ecpricetext((int)$obj->id); foreach (Language::getLanguages(false) as $lang) { $this->fields_value['pricetext'][(int)$lang['id_lang']] = $info->pricetext[(int)$lang['id_lang']]; } } else { $this->fields_value[$inputfield['name']] = $obj->$inputfield['name']; } } //return parent::renderForm(); $this->initPack(); return $this->initFormPack().'<div>'.parent::renderForm().'</div>'; } public function getPackItems($packGroupId = null) { $pack_items = array(); if (!$packGroupId) { $names_input = Tools::getValue('namePackItems'); $ids_input = Tools::getValue('inputPackItems'); if (!$names_input || !$ids_input) { return array(); } // ids is an array of string with format : QTYxID $ids = array_unique(explode('-', $ids_input)); $names = array_unique(explode('¤', $names_input)); if (!empty($ids)) { $length = count($ids); for ($i = 0; $i < $length; $i++) { if (!empty($ids[$i]) && !empty($names[$i])) { list($pack_items[$i]['pack_quantity'], $pack_items[$i]['id']) = explode('x', $ids[$i]); $exploded_name = explode('x', $names[$i]); $pack_items[$i]['name'] = $exploded_name[1]; } } } } else { $ecpricetexts = Ecpricetext::getItems($packGroupId); $pack_quantity = 1; $i = 0; foreach ($ecpricetexts as $pack_item) { $pack_items[$i]['id'] = $pack_item->id_product; $pack_items[$i]['pack_quantity'] = $pack_quantity; $pack_items[$i]['name'] = $pack_item->product_name; $pack_items[$i]['reference'] = 'Product_id'.$pack_item->id_product; $pack_items[$i]['id_product_attribute'] = 0; $product = new Product($pack_item->id_product, false, $this->id_lang); $cover = Product::getCover($pack_item->id_product); $pack_items[$i]['image'] = Context::getContext()->link->getImageLink($product->link_rewrite, $cover['id_image'], ImageType::getFormatedName('small')); $i++; } } return $pack_items; } protected function initPack() { $packGroupId = Tools::getValue('id_ecpricetext'); $ecpricetext = new Ecpricetext($packGroupId); $ecpricetexts = array($ecpricetext); $pack_quantity = 1; $input_pack_items = ''; if (Tools::getValue('inputPackItems')) { $input_pack_items = Tools::getValue('inputPackItems'); } else { foreach ($ecpricetexts as $pack_item) { $input_pack_items .= $pack_quantity.'x'.$pack_item->id_product.'-'; } } $this->tpl_form_vars['input_pack_items'] = $input_pack_items; $input_namepack_items = ''; if (Tools::getValue('namePackItems')) { $input_namepack_items = Tools::getValue('namePackItems'); } else { foreach ($ecpricetexts as $pack_item) { $input_namepack_items .= $pack_quantity.' x '.$pack_item->product_name.'¤'; } } $this->tpl_form_vars['input_namepack_items'] = $input_namepack_items; } public function initFormPack() { $data = $this->context->smarty->createTemplate(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/pack.tpl', $this->context->smarty); if (Tools::getValue('namePackItems')) { $input_pack_items = Tools::getValue('inputPackItems'); $input_namepack_items = Tools::getValue('namePackItems'); $pack_items = $this->getPackItems(); } else { $packGroupId = Tools::getValue('id_ecpricetext'); $pack_items = $this->getPackItems($packGroupId); $input_namepack_items = ''; $input_pack_items = ''; foreach ($pack_items as $pack_item) { $input_pack_items .= $pack_item['pack_quantity'].'x'.$pack_item['id'].'x'.'0'.'-'; $input_namepack_items .= $pack_item['pack_quantity'].' x '.$pack_item['name'].'¤'; } } $data->assign(array( 'input_pack_items' => $input_pack_items, 'input_namepack_items' => $input_namepack_items, 'pack_items' => $pack_items, 'product_type' => (int)Tools::getValue('type_product'), 'id_lang_default' => Configuration::get('PS_LANG_DEFAULT'), 'tabs_preloaded' => array('Pack' => 7,), 'form_action' => $this->context->link->getAdminLink('AdminEcPriceText').'&'.'action='.'addproductrule', )); return $data->fetch(); } public function processAjaxProductsList() { $query = Tools::getValue('q', false); if (!$query || $query == '' || Tools::strlen($query) < 1) { die(); } if ($pos = strpos($query, ' (ref:')) { $query = Tools::substr($query, 0, $pos); } $excludeIds = Tools::getValue('excludeIds', false); if ($excludeIds && $excludeIds != 'NaN') { $excludeIds = implode(',', array_map('intval', explode(',', $excludeIds))); } else { $excludeIds = ''; } // Excluding downloadable products from packs because download from pack is not supported $excludeVirtuals = (bool)Tools::getValue('excludeVirtuals', false); $exclude_packs = (bool)Tools::getValue('exclude_packs', false); $sql = 'SELECT p.`id_product`, pl.`link_rewrite`, p.`reference`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, p.`cache_default_attribute` FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product = p.id_product AND pl.id_lang = '.(int)Context::getContext()->language->id.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 (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)Context::getContext()->language->id.') WHERE (pl.name LIKE \'%'.pSQL($query).'%\' OR p.reference LIKE \'%'.pSQL($query).'%\')'. (!empty($excludeIds) ? ' AND p.id_product NOT IN ('.pSQL($excludeIds).') ' : ' '). ($excludeVirtuals ? 'AND p.id_product NOT IN (SELECT pd.id_product FROM `'._DB_PREFIX_.'product_download` pd WHERE (pd.id_product = p.id_product))' : ''). ($exclude_packs ? 'AND (p.cache_is_pack IS NULL OR p.cache_is_pack = 0)' : ''). ' GROUP BY p.id_product'; $items = Db::getInstance()->executeS($sql); if ($items && ($excludeIds || strpos($_SERVER['HTTP_REFERER'], 'AdminScenes') !== false)) { foreach ($items as $item) { echo trim($item['name']).(!empty($item['reference']) ? ' (ref: '.$item['reference'].')' : '').'|'.(int)($item['id_product'])."\n"; } } elseif ($items) { // packs $results = array(); foreach ($items as $item) { $product = array( 'id' => (int)($item['id_product']), 'name' => $item['name'], 'ref' => (!empty($item['reference']) ? $item['reference'] : ''), 'image' => str_replace('http://', Tools::getShopProtocol(), Context::getContext()->link->getImageLink($item['link_rewrite'], $item['id_image'])), ); array_push($results, $product); } $results = array_values($results); echo Tools::jsonEncode($results); } else { echo Tools::jsonEncode(new stdClass); } die(); } }
💾 保存文件
← 返回文件管理器