/** * @param Offer $obj * @throws Exception * @throws PrestaShopException * @throws SmartyException */ public function initFormProducts($obj) { $offer = $obj; $data = $this->createTemplate($this->tpl_form); // Selected shops $selected_products = array(); $products = AphOffer::getProductsLight($this->context->language->id, $offer->id); if (!empty($products)) { foreach ($products as $product) { $selected_products[] = $product['id_product']; } } // Generate category selection tree $tree = new HelperTreeProducts('products-tree', $this->l('Seleziona servizio')); $tree->setAttribute('selected_products', $selected_products); $tree->setInputName('checkBoxProductAsso_offer'); $tree->setSelectedProducts($selected_products); $tree->setUseShopRestriction(true); $data->assign('product_tree', $tree->render()); // if ($post_products = Tools::getValue('inputProducts')) { // $post_products_tab = explode('-', $post_products); // foreach ($post_products_tab as $product_id) { // if (!$this->haveThisProduct($product_id, $products) && $product = AphOffer::getProductById($product_id)) { // $products[] = $product; // } // } // } // $data->assign('products', $products); $data->assign(array('offer' => $offer, 'link' => $this->context->link, 'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP)); $this->tpl_form_vars['custom_form'] = $data->fetch(); }
/** * Get view * * @return string */ public function renderList() { $current_date = DateTime::createFromFormat('Y-m-d', Tools::getValue('date')) ? Tools::getValue('date') : date('Y-m-d'); //get businnes hours about Context::getContext()->shop->id; $store = Db::getInstance()->getRow(' SELECT st.hours FROM ' . _DB_PREFIX_ . 'store_shop ss LEFT JOIN `' . _DB_PREFIX_ . 'store` st ON (ss.`id_store` = st.`id_store`) WHERE ss.`id_shop` = ' . (int) Context::getContext()->shop->id); $hours = json_decode($store['hours'], true); $minTime = '12:00:00'; $maxTime = '12:00:00'; if (!empty($hours) && is_array($hours)) { foreach ($hours as $hour) { if ($hour[1]['o'] == 'X' || $hour[1]['c'] == 'X') { continue; } $hour[1]['o'] = $hour[1]['o'] . ':00'; $hour[1]['c'] = $hour[1]['c'] . ':00'; if ($hour[1]['o'] < $minTime) { $minTime = $hour[1]['o']; } if ($hour[1]['c'] > $maxTime) { $maxTime = $hour[1]['c']; } if ($hour[2]['o'] == 'X' || $hour[2]['c'] == 'X') { continue; } $hour[2]['o'] = $hour[2]['o'] . ':00'; $hour[2]['c'] = $hour[2]['c'] . ':00'; if ($hour[2]['o'] < $minTime) { $minTime = $hour[2]['o']; } if ($hour[2]['c'] > $maxTime) { $maxTime = $hour[2]['c']; } } } if ($minTime == '12:00:00') { $minTime = '08:00:00'; } if ($maxTime == '12:00:00') { $maxTime = '22:00:00'; } $this->id_current_product = (int) Tools::getValue('id_product'); if ((bool) $this->id_current_product) { $product = new Product($this->id_current_product, false, (int) Context::getContext()->language->id); $this->context->smarty->assign('id_current_product', $product->id); $this->context->smarty->assign('product_name', $product->name); } // Generate product selection tree $tree = new HelperTreeProducts('products-tree', $this->l('Seleziona servizio')); //$tree->setNodeFolderTemplate('tree_node_folder_radio.tpl'); $tree->setNodeItemTemplate('tree_node_item_radio_products.tpl'); if ((bool) $this->id_current_product) { $tree->setAttribute('selected_product', array($this->id_current_product)); $tree->setSelectedProducts(array($this->id_current_product)); } $tree->setInputName('id_product'); $tree->setUseRadioBox(true); $tree->setUseActiveProducts(true); $tree->setShowPrice(false); $tree->setUseShopRestriction(true); $this->context->smarty->assign('product_tree', $tree->render()); $jsVars = array('language' => $this->context->language->iso_code, 'defaultDate' => $current_date, 'minTime' => $minTime, 'maxTime' => $maxTime, 'slotDuration' => '00:' . Configuration::get('APH_CALENDAR_TIME_SLICE') . ':00', 'id_current_product' => (int) $this->id_current_product); $this->setJsVars($jsVars); $this->content .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/controllers/custom_prices/calendar.tpl'); return parent::renderList(); }
/** * Get view * * @return string */ public function initContent() { if (Context::getContext()->employee->id_profile == Configuration::get('APH_PROFILE_SITE_OWNER')) { $shops = array(); //$_shops = Shop::getShops(true, null, true); $_shops = Shop::getCompleteListOfShopsID(); foreach ($_shops as $id_shop) { if ($id_shop == Configuration::get('PS_SHOP_DEFAULT')) { continue; } $shop = new Shop($id_shop); $shops[$id_shop] = $shop->name; } asort($shops); $this->context->smarty->assign('shops', $shops); } if ($this->display == 'edit') { $obj = $this->loadObject(true); $this->context->smarty->assign(array('obj' => $obj)); // Selected products $selected_products = array(); $products = AphTool::getProducts($obj->id); if (!empty($products)) { foreach ($products as $product) { $selected_products[] = $product['id_product']; } } } if ($this->display == 'add' || $this->display == 'edit') { // Generate category selection tree $tree = new HelperTreeProducts('products-tree', $this->l('Seleziona servizio')); $tree->setInputName('checkBoxProductAsso_tool'); if (!empty($selected_products)) { $tree->setAttribute('selected_products', $selected_products); $tree->setSelectedProducts($selected_products); } $tree->setUseShopRestriction(true); $this->context->smarty->assign('product_tree', $tree->render()); $languages = Language::getLanguages(true); $this->context->smarty->assign(array("id_lang_default" => Configuration::get('PS_LANG_DEFAULT'), 'tpl_dir' => $this->tpl_dir, "languages" => $languages)); $this->content .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . "/views/templates/admin/controllers/tools/form.tpl"); } parent::initContent(); }
/** * @param Offer $obj * @throws Exception * @throws PrestaShopException * @throws SmartyException */ public function initFormProducts($obj) { $employee = $obj; $data = $this->createTemplate('products.tpl'); // Selected products $selected_products = array(); $products = AphEmployeeProduct::getProductsByEmployee($employee->id); if (!empty($products)) { foreach ($products as $product) { $selected_products[] = $product['id_product']; } } // Generate category selection tree $tree = new HelperTreeProducts('products-tree', $this->l('Seleziona servizio')); $tree->setAttribute('selected_products', $selected_products); $tree->setInputName('checkBoxProductAsso_employee'); $tree->setSelectedProducts($selected_products); $tree->setUseShopRestriction(true); if (!empty($employee->id)) { $shops = $employee->getAssociatedShops(); if (!empty($shops)) { $tree->setShop(new Shop($shops[0])); } } $data->assign('product_tree', $tree->render()); $data->assign(array('dipendente' => $employee, 'link' => $this->context->link, 'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP)); $this->tpl_form_vars['custom_form'] = $data->fetch(); }