/** * Create a link to a product * * @param mixed $product Product object (can be an ID product, but deprecated) * @param string $alias * @param string $category * @param string $ean13 * @param int $id_lang * @param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart * @param int $ipa ID product attribute * @return string */ public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null, $ipa = 0, $force_routes = false, $relative_protocol = false, $add_anchor = false) { $dispatcher = Dispatcher::getInstance(); if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop, null, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop); if (!is_object($product)) { if (is_array($product) && isset($product['id_product'])) { $product = new Product($product['id_product'], false, $id_lang, $id_shop); } elseif ((int) $product) { $product = new Product((int) $product, false, $id_lang, $id_shop); } else { throw new PrestaShopException('Invalid product vars'); } } // Set available keywords $params = array(); $params['id'] = $product->id; $params['rewrite'] = !$alias ? $product->getFieldByLang('link_rewrite') : $alias; $params['ean13'] = !$ean13 ? $product->ean13 : $ean13; $params['meta_keywords'] = Tools::str2url($product->getFieldByLang('meta_keywords')); $params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title')); if ($dispatcher->hasKeyword('product_rule', $id_lang, 'manufacturer', $id_shop)) { $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer)); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'supplier', $id_shop)) { $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier)); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'price', $id_shop)) { $params['price'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specificPrice); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'tags', $id_shop)) { $params['tags'] = Tools::str2url($product->getTags($id_lang)); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'category', $id_shop)) { $params['category'] = !is_null($product->category) && !empty($product->category) ? Tools::str2url($product->category) : Tools::str2url($category); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'reference', $id_shop)) { $params['reference'] = Tools::str2url($product->reference); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'categories', $id_shop)) { $params['category'] = !$category ? $product->category : $category; $cats = array(); foreach ($product->getParentCategories($id_lang) as $cat) { if (!in_array($cat['id_category'], Link::$category_disable_rewrite)) { //remove root and home category from the URL $cats[] = $cat['link_rewrite']; } } $params['categories'] = implode('/', $cats); } $anchor = $ipa ? $product->getAnchor((int) $ipa, (bool) $add_anchor) : ''; return $url . $dispatcher->createUrl('product_rule', $id_lang, $params, $force_routes, $anchor, $id_shop); }
} elseif (in_array(CAT_HANDBAG, $catIds)) { $category = 'Handbag'; } $doc->product_link = $productObj->getLink(); $idImage = $productObj->getCoverWs(); if ($idImage) { $idImage = $productObj->id . '-' . $idImage; } else { $idImage = Language::getIsoById(1) . '-default'; } $thickbox_image = $link->getImageLink($productObj->link_rewrite, $idImage, 'thickbox'); $large_image = $link->getImageLink($productObj->link_rewrite, $idImage, 'large'); $id_manufacturer = $productObj->id_manufacturer; $manufacturer = ''; if (!empty($id_manufacturer)) { $manufacturer = Manufacturer::getNameById($id_manufacturer); } $productRec = array($id_product, $productObj->reference, $productObj->supplier_reference, $productObj->name, $productObj->getLink(), $productObj->getPriceWithoutReduct(), round($productObj->getPrice()), round($mrp_in_rs), round($offer_price_in_rs), strip_tags($productObj->description), '0', $availability, $manufacturer, $category, $categories, $color, $fabric, (int) $productObj->active === 1 ? 'ACTIVE' : 'INACTIVE', $quantity, $productObj->shipping_sla, $productObj->is_customizable, $large_image, $thickbox_image, date('Y-m-d', strtotime($productObj->date_add))); $images = $productObj->getImages(1); foreach ($images as $image) { $oImage = $link->getImageLink($productObj->link_rewrite, $image['id_image'], 'thickbox'); if ($thickbox_image !== $oImage) { array_push($productRec, $oImage); } } //echo '"'.implode($productRec,'","').'"'; //echo PHP_EOL; fputcsv($outstream, $productRec, ',', '"'); ob_flush(); flush(); }
public function ajaxCall() { //sleep(1); global $smarty, $cookie; $selectedFilters = $this->getSelectedFilters(); $id_parent = (int) Tools::getValue('id_category', Tools::getValue('id_category_layered', 1)); $id_manufacturer = Tools::getValue('id_manufacturer', false); $sortInfo = ''; if (Tools::getValue('orderby') && Tools::getValue('orderway')) { $sortInfo = Tools::getProductsOrder('by', Tools::getValue('orderby')) . ':' . Tools::getProductsOrder('way', Tools::getValue('orderway')); } //echo print_r($selectedFilters); //$products = $this->getProductByFilters($selectedFilters); $resultSet = $this->getResults($id_parent, $this->search_query, $id_manufacturer, $selectedFilters); $products = $resultSet->getData(); $products = $products['response']['docs']; $nbProducts = $resultSet->getNumFound(); $range = 3; /* how many pages around page selected */ $n = (int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')); $p = Tools::getValue('p', 1); if ($p < 0) { $p = 0; } if ($p > $nbProducts / $n) { $p = ceil($nbProducts / $n); } $pages_nb = ceil($nbProducts / (int) $n); $start = (int) ($p - $range); if ($start < 1) { $start = 1; } $stop = (int) ($p + $range); if ($stop > $pages_nb) { $stop = (int) $pages_nb; } $smarty->assign('nb_products', $nbProducts); $pagination_infos = array('pages_nb' => (int) $pages_nb, 'p' => (int) $p, 'n' => (int) $n, 'range' => (int) $range, 'start' => (int) $start, 'stop' => (int) $stop, 'nArray' => $nArray = (int) Configuration::get('PS_PRODUCTS_PER_PAGE') != 10 ? array((int) Configuration::get('PS_PRODUCTS_PER_PAGE'), 10, 20, 50) : array(10, 20, 50)); $smarty->assign($pagination_infos); $smarty->assign('static_token', Tools::getToken(false)); $smarty->assign('products', $products); $category = new Category((int) $id_parent); $selectedCategory = $category->getName(1); $productsTitle = $this->search_query ? $this->search_query : ($id_manufacturer ? Manufacturer::getNameById($id_manufacturer, 1) : $selectedCategory); $smarty->assign('lazy', 0); $nextPage = $p + 1; if ($p == $stop) { $nextPage = 0; } $smarty->assign('nextPage', $nextPage); $autoLoad = Tools::getValue('al', false); header('Content-type: application/json'); if ($cookie->image_size == IMAGE_SIZE_LARGE) { $productListContent = $smarty->fetch(_PS_THEME_DIR_ . 'product-list-page.tpl'); } else { $productListContent = $smarty->fetch(_PS_THEME_DIR_ . 'product-list-page-small.tpl'); } if ($autoLoad) { $smarty->assign('autoload', 1); return Tools::jsonEncode(array('productList' => $productListContent, 'nextPage' => $nextPage)); } else { $smarty->assign('autoload', 0); return Tools::jsonEncode(array('filtersBlock' => $this->generateFiltersBlock($selectedFilters), 'productList' => $productListContent, 'pagination' => $smarty->fetch(_PS_THEME_DIR_ . 'pagination.tpl'), 'totalItems' => $nbProducts, 'sortInfo' => $sortInfo, 'productsTitle' => $productsTitle, 'nextPage' => $nextPage)); } // return '<div id="layered_ajax_column">'.$this->generateFiltersBlock($selectedFilters).'</div><div id="layered_ajax_products">'.$smarty->fetch(_PS_THEME_DIR_.'product-list.tpl').'</div>'; }
function displayFormInformations($obj, $currency) { parent::displayForm(false); global $currentIndex, $cookie, $link; $default_country = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT')); $iso = Language::getIsoById((int) $cookie->id_lang); $has_attribute = false; $qty_state = 'readonly'; $qty = Attribute::getAttributeQty($this->getFieldValue($obj, 'id_product')); if ($qty === false) { if (Validate::isLoadedObject($obj)) { $qty = $this->getFieldValue($obj, 'quantity'); } else { $qty = 1; } $qty_state = ''; } else { $has_attribute = true; } $cover = Product::getCover($obj->id); $this->_applyTaxToEcotax($obj); echo ' <div class="tab-page" id="step1"> <h4 class="tab">1. ' . $this->l('Info.') . '</h4> <script type="text/javascript"> $(document).ready(function() { updateCurrentText(); updateFriendlyURL(); $.ajax({ url: "' . dirname($currentIndex) . '/ajax.php", cache: false, dataType: "json", data: "ajaxProductManufacturers=1", success: function(j) { var options = $("select#id_manufacturer").html(); if (j) for (var i = 0; i < j.length; i++) options += \'<option value="\' + j[i].optionValue + \'">\' + j[i].optionDisplay + \'</option>\'; $("select#id_manufacturer").html(options); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(\'Manufacturer ajax error: \'+textStatus); } }); $.ajax({ url: "' . dirname($currentIndex) . '/ajax.php", cache: false, dataType: "json", data: "ajaxProductSuppliers=1", success: function(j) { var options = $("select#id_supplier").html(); if (j) for (var i = 0; i < j.length; i++) options += \'<option value="\' + j[i].optionValue + \'">\' + j[i].optionDisplay + \'</option>\'; $("select#id_supplier").html(options); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(\'Supplier ajax error: \'+textStatus); } }); if ($(\'#available_for_order\').is(\':checked\')){ $(\'#show_price\').attr(\'checked\', \'checked\'); $(\'#show_price\').attr(\'disabled\', \'disabled\'); } else { $(\'#show_price\').attr(\'disabled\', \'\'); } }); </script> <b>' . $this->l('Product global information') . '</b> - '; $preview_url = ''; if (isset($obj->id)) { $preview_url = $link->getProductLink($this->getFieldValue($obj, 'id'), $this->getFieldValue($obj, 'link_rewrite', $this->_defaultFormLanguage), Category::getLinkRewrite($this->getFieldValue($obj, 'id_category_default'), (int) $cookie->id_lang)); if (!$obj->active) { $admin_dir = dirname($_SERVER['PHP_SELF']); $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1); $token = Tools::encrypt('PreviewProduct' . $obj->id); $preview_url .= $obj->active ? '' : '&adtoken=' . $token . '&ad=' . $admin_dir; } echo ' <a href="index.php?tab=AdminCatalog&id_product=' . $obj->id . '&deleteproduct&token=' . $this->token . '" style="float:right;" onclick="return confirm(\'' . $this->l('Are you sure?', __CLASS__, true, false) . '\');"> <img src="../img/admin/delete.gif" alt="' . $this->l('Delete this product') . '" title="' . $this->l('Delete this product') . '" /> ' . $this->l('Delete this product') . '</a> <a href="' . $preview_url . '" target="_blank"><img src="../img/admin/details.gif" alt="' . $this->l('View product in shop') . '" title="' . $this->l('View product in shop') . '" /> ' . $this->l('View product in shop') . '</a>'; if (file_exists(_PS_MODULE_DIR_ . 'statsproduct/statsproduct.php')) { echo ' - <a href="index.php?tab=AdminStats&module=statsproduct&id_product=' . $obj->id . '&token=' . Tools::getAdminToken('AdminStats' . (int) Tab::getIdFromClassName('AdminStats') . (int) $cookie->id_employee) . '"><img src="../modules/statsproduct/logo.gif" alt="' . $this->l('View product sales') . '" title="' . $this->l('View product sales') . '" /> ' . $this->l('View product sales') . '</a>'; } } echo ' <hr class="clear"/> <br /> <table cellpadding="5" style="width: 50%; float: left; margin-right: 20px; border-right: 1px solid #E0D0B1;"> <tr> <td class="col-left">' . $this->l('Name:') . '</td> <td style="padding-bottom:5px;" class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input size="43" type="text" id="name_' . $language['id_lang'] . '" name="name_' . $language['id_lang'] . '" value="' . stripslashes(htmlspecialchars($this->getFieldValue($obj, 'name', $language['id_lang']))) . '"' . (!$obj->id ? ' onkeyup="if (isArrowKey(event)) return; copy2friendlyURL();"' : '') . ' onkeyup="if (isArrowKey(event)) return; updateCurrentText();" onchange="updateCurrentText();" /><sup> *</sup> <span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' </td> </tr> <tr> <td class="col-left">' . $this->l('Reference:') . '</td> <td style="padding-bottom:5px;"> <input size="55" type="text" name="reference" value="' . htmlentities($this->getFieldValue($obj, 'reference'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 44px;" /> <span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#\\<span class="hint-pointer"> </span></span> </td> </tr> <tr> <td class="col-left">' . $this->l('Supplier Reference:') . '</td> <td style="padding-bottom:5px;"> <input size="55" type="text" name="supplier_reference" value="' . htmlentities($this->getFieldValue($obj, 'supplier_reference'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 44px;" /> <span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#\\<span class="hint-pointer"> </span></span> </td> </tr> <tr> <td class="col-left">' . $this->l('EAN13 or JAN:') . '</td> <td style="padding-bottom:5px;"> <input size="55" maxlength="13" type="text" name="ean13" value="' . htmlentities($this->getFieldValue($obj, 'ean13'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 5px;" /> <span class="small">' . $this->l('(Europe, Japan)') . '</span> </td> </tr> <tr> <td class="col-left">' . $this->l('UPC:') . '</td> <td style="padding-bottom:5px;"> <input size="55" maxlength="12" type="text" name="upc" value="' . htmlentities($this->getFieldValue($obj, 'upc'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 5px;" /> <span class="small">' . $this->l('(US, Canada)') . '</span> </td> </tr> <tr> <td class="col-left">' . $this->l('Location (warehouse):') . '</td> <td style="padding-bottom:5px;"> <input size="55" type="text" name="location" value="' . htmlentities($this->getFieldValue($obj, 'location'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 44px;" /> </td> </tr> <tr> <td class="col-left">' . $this->l('Width ( package ) :') . '</td> <td style="padding-bottom:5px;"> <input size="6" maxlength="6" name="width" type="text" value="' . htmlentities($this->getFieldValue($obj, 'width'), ENT_COMPAT, 'UTF-8') . '" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_DIMENSION_UNIT') . ' </td> </tr> <tr> <td class="col-left">' . $this->l('Height ( package ) :') . '</td> <td style="padding-bottom:5px;"> <input size="6" maxlength="6" name="height" type="text" value="' . htmlentities($this->getFieldValue($obj, 'height'), ENT_COMPAT, 'UTF-8') . '" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_DIMENSION_UNIT') . ' </td> </tr> <tr> <td class="col-left">' . $this->l('Deep ( package ) :') . '</td> <td style="padding-bottom:5px;"> <input size="6" maxlength="6" name="depth" type="text" value="' . htmlentities($this->getFieldValue($obj, 'depth'), ENT_COMPAT, 'UTF-8') . '" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_DIMENSION_UNIT') . ' </td> </tr> <tr> <td class="col-left">' . $this->l('Weight ( package ) :') . '</td> <td style="padding-bottom:5px;"> <input size="6" maxlength="6" name="weight" type="text" value="' . htmlentities($this->getFieldValue($obj, 'weight'), ENT_COMPAT, 'UTF-8') . '" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_WEIGHT_UNIT') . ' </td> </tr> </table> <table cellpadding="5" style="width: 40%; float: left; margin-left: 10px;"> <tr> <td style="vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Status:') . '</td> <td style="padding-bottom:5px;"> <input style="float:left;" onclick="toggleDraftWarning(false);showOptions(true);" type="radio" name="active" id="active_on" value="1" ' . ($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/> <label for="active_on" class="t"><img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" style="float:left; padding:0px 5px 0px 5px;" />' . $this->l('Enabled') . '</label> <br class="clear" /> <input style="float:left;" onclick="toggleDraftWarning(true);showOptions(false);" type="radio" name="active" id="active_off" value="0" ' . (!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/> <label for="active_off" class="t"><img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" style="float:left; padding:0px 5px 0px 5px" />' . $this->l('Disabled') . ($obj->active ? '' : ' (<a href="' . $preview_url . '" alt="" target="_blank">' . $this->l('View product in shop') . '</a>)') . '</label> </td> </tr> <tr id="product_options" ' . (!$obj->active ? 'style="display:none"' : '') . '> <td style="vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Options:') . '</td> <td style="padding-bottom:5px;"> <input style="float: left;" type="checkbox" name="available_for_order" id="available_for_order" value="1" ' . ($this->getFieldValue($obj, 'available_for_order') ? 'checked="checked" ' : '') . ' onclick="if ($(this).is(\':checked\')){$(\'#show_price\').attr(\'checked\', \'checked\');$(\'#show_price\').attr(\'disabled\', \'disabled\');}else{$(\'#show_price\').attr(\'disabled\', \'\');}"/> <label for="available_for_order" class="t"><img src="../img/admin/products.gif" alt="' . $this->l('available for order') . '" title="' . $this->l('available for order') . '" style="float:left; padding:0px 5px 0px 5px" />' . $this->l('available for order') . '</label> <br class="clear" /> <input style="float: left;" type="checkbox" name="show_price" id="show_price" value="1" ' . ($this->getFieldValue($obj, 'show_price') ? 'checked="checked" ' : '') . ' /> <label for="show_price" class="t"><img src="../img/admin/gold.gif" alt="' . $this->l('display price') . '" title="' . $this->l('show price') . '" style="float:left; padding:0px 5px 0px 5px" />' . $this->l('show price') . '</label> <br class="clear" /> <input style="float: left;" type="checkbox" name="online_only" id="online_only" value="1" ' . ($this->getFieldValue($obj, 'online_only') ? 'checked="checked" ' : '') . ' /> <label for="online_only" class="t"><img src="../img/admin/basket_error.png" alt="' . $this->l('online only') . '" title="' . $this->l('online only') . '" style="float:left; padding:0px 5px 0px 5px" />' . $this->l('online only (not sold in store)') . '</label> </td> </tr> <tr> <td style="vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Condition:') . '</td> <td style="padding-bottom:5px;"> <select name="condition" id="condition"> <option value="new" ' . ($obj->condition == 'new' ? 'selected="selected"' : '') . '>' . $this->l('New') . '</option> <option value="used" ' . ($obj->condition == 'used' ? 'selected="selected"' : '') . '>' . $this->l('Used') . '</option> <option value="refurbished" ' . ($obj->condition == 'refurbished' ? 'selected="selected"' : '') . '>' . $this->l('Refurbished') . '</option> </select> </td> </tr> <tr> <td style="vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Manufacturer:') . '</td> <td style="padding-bottom:5px;"> <select name="id_manufacturer" id="id_manufacturer"> <option value="0">-- ' . $this->l('Choose (optional)') . ' --</option>'; if ($id_manufacturer = $this->getFieldValue($obj, 'id_manufacturer')) { echo ' <option value="' . $id_manufacturer . '" selected="selected">' . Manufacturer::getNameById($id_manufacturer) . '</option> <option disabled="disabled">----------</option>'; } echo ' </select> <a href="?tab=AdminManufacturers&addmanufacturer&token=' . Tools::getAdminToken('AdminManufacturers' . (int) Tab::getIdFromClassName('AdminManufacturers') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete product information entered?', __CLASS__, true, false) . '\');"><img src="../img/admin/add.gif" alt="' . $this->l('Create') . '" title="' . $this->l('Create') . '" /> <b>' . $this->l('Create') . '</b></a> </td> </tr> <tr> <td style="vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Supplier:') . '</td> <td style="padding-bottom:5px;"> <select name="id_supplier" id="id_supplier"> <option value="0">-- ' . $this->l('Choose (optional)') . ' --</option>'; if ($id_supplier = $this->getFieldValue($obj, 'id_supplier')) { echo ' <option value="' . $id_supplier . '" selected="selected">' . Supplier::getNameById($id_supplier) . '</option> <option disabled="disabled">----------</option>'; } echo ' </select> <a href="?tab=AdminSuppliers&addsupplier&token=' . Tools::getAdminToken('AdminSuppliers' . (int) Tab::getIdFromClassName('AdminSuppliers') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/add.gif" alt="' . $this->l('Create') . '" title="' . $this->l('Create') . '" /> <b>' . $this->l('Create') . '</b></a> </td> </tr> </table> <div class="clear"></div> <table cellpadding="5" style="width: 100%;"> <tr><td colspan="2"><hr style="width:100%;" /></td></tr>'; $this->displayPack($obj); echo ' <tr><td colspan="2"><hr style="width:100%;" /></td></tr>'; /* * Form for add a virtual product like software, mp3, etc... */ $productDownload = new ProductDownload(); if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($obj, 'id'))) { $productDownload = new ProductDownload($id_product_download); } ?> <script type="text/javascript"> // <![CDATA[ ThickboxI18nImage = '<?php echo $this->l('Image'); ?> '; ThickboxI18nOf = '<?php echo $this->l('of'); ?> '; ThickboxI18nClose = '<?php echo $this->l('Close'); ?> '; ThickboxI18nOrEscKey = '<?php echo $this->l('(or "Esc")'); ?> '; ThickboxI18nNext = '<?php echo $this->l('Next >'); ?> '; ThickboxI18nPrev = '<?php echo $this->l('< Previous'); ?> '; tb_pathToImage = '../img/loadingAnimation.gif'; //]]> </script> <script type="text/javascript" src="<?php echo _PS_JS_DIR_; ?> jquery/thickbox-modified.js"></script> <script type="text/javascript" src="<?php echo _PS_JS_DIR_; ?> jquery/ajaxfileupload.js"></script> <script type="text/javascript" src="<?php echo _PS_JS_DIR_; ?> date.js"></script> <style type="text/css"> <!-- @import url(<?php echo _PS_CSS_DIR_; ?> thickbox.css); --> </style> <script type="text/javascript"> //<![CDATA[ function toggleVirtualProduct(elt) { if (elt.checked) { $('#virtual_good').show('slow'); $('#virtual_good_more').show('slow'); getE('out_of_stock_1').checked = 'checked'; getE('out_of_stock_2').disabled = 'disabled'; getE('out_of_stock_3').disabled = 'disabled'; getE('label_out_of_stock_2').setAttribute('for', ''); getE('label_out_of_stock_3').setAttribute('for', ''); } else { $('#virtual_good').hide('slow'); $('#virtual_good_more').hide('slow'); getE('out_of_stock_2').disabled = false; getE('out_of_stock_3').disabled = false; getE('label_out_of_stock_2').setAttribute('for', 'out_of_stock_2'); getE('label_out_of_stock_3').setAttribute('for', 'out_of_stock_3'); } } function uploadFile() { $.ajaxFileUpload ( { url:'./uploadProductFile.php', secureuri:false, fileElementId:'virtual_product_file', dataType: 'xml', success: function (data, status) { data = data.getElementsByTagName('return')[0]; var result = data.getAttribute("result"); var msg = data.getAttribute("msg"); var fileName = data.getAttribute("filename"); if (result == "error") { $("#upload-confirmation").html('<p>error: ' + msg + '</p>'); } else { $('#virtual_product_file').remove(); $('#virtual_product_file_label').hide(); $('#file_missing').hide(); new_href = $('#delete_downloadable_product').attr('href').replace('%26deleteVirtualProduct%3Dtrue', '%26file%3D'+msg+'%26deleteVirtualProduct%3Dtrue'); $('#delete_downloadable_product').attr('href', new_href); $('#delete_downloadable_product').show(); $('#virtual_product_name').attr('value', fileName); $('#upload-confirmation').html( '<a class="link" href="get-file-admin.php?file='+msg+'&filename='+fileName+'"><?php echo $this->l('The file'); ?> "' + fileName + '" <?php echo $this->l('has successfully been uploaded'); ?> </a>' + '<input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="' + msg + '" />'); } } } ); } //]]> </script> <?php echo ' <script type="text/javascript" src="../js/price.js"></script> <script type="text/javascript"> var newLabel = \'' . $this->l('New label') . '\'; var choose_language = \'' . $this->l('Choose language:') . '\'; var required = \'' . $this->l('required') . '\'; var customizationUploadableFileNumber = ' . (int) $this->getFieldValue($obj, 'uploadable_files') . '; var customizationTextFieldNumber = ' . (int) $this->getFieldValue($obj, 'text_fields') . '; var uploadableFileLabel = 0; var textFieldLabel = 0; </script>'; ?> <tr> <td colspan="2"> <p><input type="checkbox" id="is_virtual_good" name="is_virtual_good" value="true" onclick="toggleVirtualProduct(this);" <?php if (($productDownload->id or Tools::getValue('is_virtual_good') == 'true') and $productDownload->active) { echo 'checked="checked"'; } ?> /> <label for="is_virtual_good" class="t bold" style="color: black;"><?php echo $this->l('Is this a downloadable product?'); ?> </label></p> <div id="virtual_good" <?php if (!$productDownload->id or !$productDownload->active) { echo 'style="display:none;"'; } ?> > <?php if (!ProductDownload::checkWritableDir()) { ?> <p class="alert"> <?php echo $this->l('Your download repository is not writable.'); ?> <br/> <?php echo realpath(_PS_DOWNLOAD_DIR_); ?> </p> <?php } else { ?> <?php if ($productDownload->id) { echo '<input type="hidden" id="virtual_product_id" name="virtual_product_id" value="' . $productDownload->id . '" />'; } ?> <p class="block"> <?php if (!$productDownload->checkFile()) { ?> <div style="padding:5px;width:50%;float:left;margin-right:20px;border-right:1px solid #E0D0B1"> <?php if ($productDownload->id) { ?> <p class="alert" id="file_missing"> <?php echo $this->l('This product is missing'); ?> :<br/> <?php echo realpath(_PS_DOWNLOAD_DIR_) . '/' . $productDownload->physically_filename; ?> </p> <?php } ?> <p><?php $max_upload = (int) ini_get('upload_max_filesize'); $max_post = (int) ini_get('post_max_size'); $upload_mb = min($max_upload, $max_post); echo $this->l('Your server\'s maximum upload file size is') . ': ' . $upload_mb . $this->l('Mb'); ?> </p> <?php if (!strval(Tools::getValue('virtual_product_filename'))) { ?> <label id="virtual_product_file_label" for="virtual_product_file" class="t"><?php echo $this->l('Upload a file'); ?> </label> <p><input type="file" id="virtual_product_file" name="virtual_product_file" onchange="uploadFile();" /></p> <?php } ?> <div id="upload-confirmation"> <?php if ($up_filename = strval(Tools::getValue('virtual_product_filename'))) { ?> <input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="<?php echo $up_filename; ?> " /> <?php } ?> </div> <a id="delete_downloadable_product" style="display:none;" href="confirm.php?height=200&width=300&modal=true&referer=<?php echo rawurlencode($_SERVER['REQUEST_URI'] . '&deleteVirtualProduct=true'); ?> " class="thickbox red" title="<?php echo $this->l('Delete this file'); ?> "><?php echo $this->l('Delete this file'); ?> </a> <?php } else { ?> <input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="<?php echo $productDownload->physically_filename; ?> " /> <?php echo $this->l('This is the link') . ': ' . $productDownload->getHtmlLink(false, true); ?> <a href="confirm.php?height=200&width=300&modal=true&referer=<?php echo rawurlencode($_SERVER['REQUEST_URI'] . '&deleteVirtualProduct=true'); ?> " class="thickbox red" title="<?php echo $this->l('Delete this file'); ?> "><?php echo $this->l('Delete this file'); ?> </a> <?php } // check if file exists ?> </p> <p class="block"> <label for="virtual_product_name" class="t"><?php echo $this->l('Filename'); ?> </label> <input type="text" id="virtual_product_name" name="virtual_product_name" style="width:200px" value="<?php echo $productDownload->id > 0 ? $productDownload->display_filename : htmlentities(Tools::getValue('virtual_product_name'), ENT_COMPAT, 'UTF-8'); ?> " /> <span class="hint" name="help_box" style="display:none;"><?php echo $this->l('The full filename with its extension (e.g., Book.pdf)'); ?> </span> </p> </div> <div id="virtual_good_more" style="<?php if (!$productDownload->id or !$productDownload->active) { echo 'display:none;'; } ?> padding:5px;width:40%;float:left;margin-left:10px"> <p class="block"> <label for="virtual_product_nb_downloable" class="t"><?php echo $this->l('Number of downloads'); ?> </label> <input type="text" id="virtual_product_nb_downloable" name="virtual_product_nb_downloable" value="<?php echo $productDownload->id > 0 ? $productDownload->nb_downloadable : htmlentities(Tools::getValue('virtual_product_nb_downloable'), ENT_COMPAT, 'UTF-8'); ?> " class="" size="6" /> <span class="hint" name="help_box" style="display:none"><?php echo $this->l('Number of authorized downloads per customer'); ?> </span> </p> <p class="block"> <label for="virtual_product_expiration_date" class="t"><?php echo $this->l('Expiration date'); ?> </label> <input type="text" id="virtual_product_expiration_date" name="virtual_product_expiration_date" value="<?php echo $productDownload->id > 0 ? (!empty($productDownload->date_expiration) and $productDownload->date_expiration != '0000-00-00 00:00:00') ? date('Y-m-d', strtotime($productDownload->date_expiration)) : '' : htmlentities(Tools::getValue('virtual_product_expiration_date'), ENT_COMPAT, 'UTF-8'); ?> " size="11" maxlength="10" autocomplete="off" /> <?php echo $this->l('Format: YYYY-MM-DD'); ?> <span class="hint" name="help_box" style="display:none"><?php echo $this->l('No expiration date if you leave this blank'); ?> </span> </p> <p class="block"> <label for="virtual_product_nb_days" class="t"><?php echo $this->l('Number of days'); ?> </label> <input type="text" id="virtual_product_nb_days" name="virtual_product_nb_days" value="<?php echo $productDownload->id > 0 ? $productDownload->nb_days_accessible : htmlentities(Tools::getValue('virtual_product_nb_days'), ENT_COMPAT, 'UTF-8'); ?> " class="" size="4" /><sup> *</sup> <span class="hint" name="help_box" style="display:none"><?php echo $this->l('How many days this file can be accessed by customers'); ?> - <em>(<?php echo $this->l('set to zero for unlimited access'); ?> )</em></span> </p> </div> <?php } // check if download directory is writable ?> </div> </td> </tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr> <script type="text/javascript"> if ($('#is_virtual_good').attr('checked')) { $('#virtual_good').show('slow'); $('#virtual_good_more').show('slow'); } </script> <?php echo ' <tr> <td class="col-left">' . $this->l('Pre-tax wholesale price:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" name="wholesale_price" type="text" value="' . htmlentities($this->getFieldValue($obj, 'wholesale_price'), ENT_COMPAT, 'UTF-8') . '" onchange="this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' <span style="margin-left:10px">' . $this->l('The wholesale price at which you bought this product') . '</span> </td> </tr>'; echo ' <tr> <td class="col-left">' . $this->l('Pre-tax retail price:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" id="priceTE" name="price" type="text" value="' . htmlentities($this->getFieldValue($obj, 'price'), ENT_COMPAT, 'UTF-8') . '" onchange="this.value = this.value.replace(/,/g, \'.\');" onkeyup="if (isArrowKey(event)) return; calcPriceTI();" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . '<sup> *</sup> <span style="margin-left:2px">' . $this->l('The pre-tax retail price to sell this product') . '</span> </td> </tr>'; $tax_rules_groups = TaxRulesGroup::getTaxRulesGroups(true); $taxesRatesByGroup = TaxRulesGroup::getAssociatedTaxRatesByIdCountry(Country::getDefaultCountryId()); $ecotaxTaxRate = Tax::getProductEcotaxRate(); echo '<script type="text/javascript">'; echo 'noTax = ' . (Tax::excludeTaxeOption() ? 'true' : 'false'), ";\n"; echo 'taxesArray = new Array ();' . "\n"; echo 'taxesArray[0] = 0', ";\n"; foreach ($tax_rules_groups as $tax_rules_group) { $tax_rate = array_key_exists($tax_rules_group['id_tax_rules_group'], $taxesRatesByGroup) ? $taxesRatesByGroup[$tax_rules_group['id_tax_rules_group']] : 0; echo 'taxesArray[' . $tax_rules_group['id_tax_rules_group'] . ']=' . $tax_rate . "\n"; } echo ' ecotaxTaxRate = ' . $ecotaxTaxRate / 100 . '; </script>'; echo ' <tr> <td class="col-left">' . $this->l('Tax rule:') . '</td> <td style="padding-bottom:5px;"> <span ' . (Tax::excludeTaxeOption() ? 'style="display:none;"' : '') . '> <select onChange="javascript:calcPriceTI(); unitPriceWithTax(\'unit\');" name="id_tax_rules_group" id="id_tax_rules_group" ' . (Tax::excludeTaxeOption() ? 'disabled="disabled"' : '') . '> <option value="0">' . $this->l('No Tax') . '</option>'; foreach ($tax_rules_groups as $tax_rules_group) { echo '<option value="' . $tax_rules_group['id_tax_rules_group'] . '" ' . ($this->getFieldValue($obj, 'id_tax_rules_group') == $tax_rules_group['id_tax_rules_group'] ? ' selected="selected"' : '') . '>' . Tools::htmlentitiesUTF8($tax_rules_group['name']) . '</option>'; } echo '</select> <a href="?tab=AdminTaxRulesGroup&addtax_rules_group&token=' . Tools::getAdminToken('AdminTaxRulesGroup' . (int) Tab::getIdFromClassName('AdminTaxRulesGroup') . (int) $cookie->id_employee) . '&id_product=' . (int) $obj->id . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/add.gif" alt="' . $this->l('Create') . '" title="' . $this->l('Create') . '" /> <b>' . $this->l('Create') . '</b></a></span> '; if (Tax::excludeTaxeOption()) { echo '<span style="margin-left:10px; color:red;">' . $this->l('Taxes are currently disabled') . '</span> (<b><a href="index.php?tab=AdminTaxes&token=' . Tools::getAdminToken('AdminTaxes' . (int) Tab::getIdFromClassName('AdminTaxes') . (int) $cookie->id_employee) . '">' . $this->l('Tax options') . '</a></b>)'; echo '<input type="hidden" value="' . (int) $this->getFieldValue($obj, 'id_tax_rules_group') . '" name="id_tax_rules_group" />'; } echo '</td> </tr> '; if (Configuration::get('PS_USE_ECOTAX')) { echo ' <tr> <td class="col-left">' . $this->l('Eco-tax (tax incl.):') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" id="ecotax" name="ecotax" type="text" value="' . $this->getFieldValue($obj, 'ecotax') . '" onkeyup="if (isArrowKey(event))return; calcPriceTE(); this.value = this.value.replace(/,/g, \'.\'); if (parseInt(this.value) > getE(\'priceTE\').value) this.value = getE(\'priceTE\').value; if (isNaN(this.value)) this.value = 0;" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' <span style="margin-left:10px">(' . $this->l('already included in price') . ')</span> </td> </tr>'; } if ($default_country->display_tax_label) { echo ' <tr ' . (Tax::excludeTaxeOption() ? 'style="display:none"' : '') . '> <td class="col-left">' . $this->l('Retail price with tax:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format % 2 != 0 ? ' ' . $currency->sign : '') . ' <input size="11" maxlength="14" id="priceTI" type="text" value="" onchange="noComma(\'priceTI\');" onkeyup="if (isArrowKey(event)) return; calcPriceTE();" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' </td> </tr>'; } else { echo '<input size="11" maxlength="14" id="priceTI" type="hidden" value="" onchange="noComma(\'priceTI\');" onkeyup="if (isArrowKey(event)) return; calcPriceTE();" />'; } echo ' <tr id="tr_unit_price"> <td class="col-left">' . $this->l('Unit price without tax:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format % 2 != 0 ? ' ' . $currency->sign : '') . ' <input size="11" maxlength="14" id="unit_price" name="unit_price" type="text" value="' . ($this->getFieldValue($obj, 'unit_price_ratio') != 0 ? Tools::ps_round($this->getFieldValue($obj, 'price') / $this->getFieldValue($obj, 'unit_price_ratio'), 2) : 0) . '" onkeyup="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\'); unitPriceWithTax(\'unit\');"/>' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' ' . $this->l('per') . ' <input size="6" maxlength="10" id="unity" name="unity" type="text" value="' . (Validate::isCleanHtml($this->getFieldValue($obj, 'unity')) ? htmlentities($this->getFieldValue($obj, 'unity'), ENT_QUOTES, 'UTF-8') : '') . '" onkeyup="if (isArrowKey(event)) return ;unitySecond();" onchange="unitySecond();"/>' . (Configuration::get('PS_TAX') && $default_country->display_tax_label ? '<span style="margin-left:15px">' . $this->l('or') . ' ' . ($currency->format % 2 != 0 ? ' ' . $currency->sign : '') . '<span id="unit_price_with_tax">0.00</span>' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' ' . $this->l('per') . ' <span id="unity_second">' . (Validate::isCleanHtml($this->getFieldValue($obj, 'unity')) ? htmlentities($this->getFieldValue($obj, 'unity'), ENT_QUOTES, 'UTF-8') : '') . '</span> ' . $this->l('with tax') : '') . '</span> <p>' . $this->l('Eg. $15 per Lb') . '</p> </td> </tr> <tr> <td class="col-left"> </td> <td style="padding-bottom:5px;"> <input type="checkbox" name="on_sale" id="on_sale" style="padding-top: 5px;" ' . ($this->getFieldValue($obj, 'on_sale') ? 'checked="checked"' : '') . 'value="1" /> <label for="on_sale" class="t">' . $this->l('Display "on sale" icon on product page and text on product listing') . '</label> </td> </tr> <tr> <td class="col-left"><b>' . $this->l('Final retail price:') . '</b></td> <td style="padding-bottom:5px;"> <span style="' . ($default_country->display_tax_label ? '' : 'display:none') . '"> ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<span id="finalPrice" style="font-weight: bold;"></span>' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . '<span' . (!Configuration::get('PS_TAX') ? ' style="display:none;"' : '') . '> (' . $this->l('tax incl.') . ')</span> </span> <span' . (!Configuration::get('PS_TAX') ? ' style="display:none;"' : '') . '>'; if ($default_country->display_tax_label) { echo ' / '; } echo ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<span id="finalPriceWithoutTax" style="font-weight: bold;"></span>' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' ' . ($default_country->display_tax_label ? '(' . $this->l('tax excl.') . ')' : '') . '</span> </td> </tr> <tr> <td class="col-left"> </td> <td> <div class="hint clear" style="display: block;width: 70%;">' . $this->l('You can define many discounts and specific price rules in the Prices tab') . '</div> </td> </tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr>'; if ((int) Configuration::get('PS_STOCK_MANAGEMENT')) { if (!$has_attribute) { if ($obj->id) { echo ' <tr><td class="col-left">' . $this->l('Stock Movement:') . '</td> <td style="padding-bottom:5px;"> <select id="id_mvt_reason" name="id_mvt_reason"> <option value="-1">--</option>'; $reasons = StockMvtReason::getStockMvtReasons((int) $cookie->id_lang); foreach ($reasons as $reason) { echo '<option rel="' . $reason['sign'] . '" value="' . $reason['id_stock_mvt_reason'] . '" ' . (Configuration::get('PS_STOCK_MVT_REASON_DEFAULT') == $reason['id_stock_mvt_reason'] ? 'selected="selected"' : '') . '>' . $reason['name'] . '</option>'; } echo '</select> <input id="mvt_quantity" type="text" name="mvt_quantity" size="3" maxlength="10" value="0"/> <span style="display:none;" id="mvt_sign"></span> </td> </tr> <tr> <td class="col-left"> </td> <td> <div class="hint clear" style="display: block;width: 70%;">' . $this->l('Choose the reason and enter the quantity that you want to increase or decrease in your stock') . '</div> </td> </tr>'; } else { echo '<tr><td class="col-left">' . $this->l('Initial stock:') . '</td> <td style="padding-bottom:5px;"> <input size="3" maxlength="10" name="quantity" type="text" value="0" /> </td>'; } echo '<tr> <td class="col-left">' . $this->l('Minimum quantity:') . '</td> <td style="padding-bottom:5px;"> <input size="3" maxlength="10" name="minimal_quantity" id="minimal_quantity" type="text" value="' . ($this->getFieldValue($obj, 'minimal_quantity') ? $this->getFieldValue($obj, 'minimal_quantity') : 1) . '" /> <p>' . $this->l('The minimum quantity to buy this product (set to 1 to disable this feature)') . '</p> </td> </tr>'; } if ($obj->id) { echo ' <tr><td class="col-left">' . $this->l('Quantity in stock:') . '</td> <td style="padding-bottom:5px;"><b>' . $qty . '</b><input type="hidden" name="quantity" value="' . $qty . '" /></td> </tr> '; } if ($has_attribute) { echo '<tr> <td class="col-left"> </td> <td> <div class="hint clear" style="display: block;width: 70%;">' . $this->l('You used combinations, for this reason you cannot edit your stock quantity here, but in the Combinations tab') . '</div> </td> </tr>'; } } else { echo '<tr> <td colspan="2">' . $this->l('The stock management is disabled') . '</td> </tr>'; echo ' <tr> <td class="col-left">' . $this->l('Minimum quantity:') . '</td> <td style="padding-bottom:5px;"> <input size="3" maxlength="10" name="minimal_quantity" id="minimal_quantity" type="text" value="' . ($this->getFieldValue($obj, 'minimal_quantity') ? $this->getFieldValue($obj, 'minimal_quantity') : 1) . '" /> <p>' . $this->l('The minimum quantity to buy this product (set to 1 to disable this feature)') . '</p> </td> </tr> '; } echo ' <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr> <tr> <td class="col-left">' . $this->l('Additional shipping cost:') . '</td> <td style="padding-bottom:5px;"> <input type="text" name="additional_shipping_cost" value="' . Tools::safeOutput($this->getFieldValue($obj, 'additional_shipping_cost')) . '" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : ''); if ($default_country->display_tax_label) { echo ' (' . $this->l('tax excl.') . ')'; } echo '<p>' . $this->l('Carrier tax will be applied.') . '</p> </td> </tr> <tr> <td class="col-left">' . $this->l('Displayed text when in-stock:') . '</td> <td style="padding-bottom:5px;" class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input size="30" type="text" id="available_now_' . $language['id_lang'] . '" name="available_now_' . $language['id_lang'] . '" value="' . stripslashes(htmlentities($this->getFieldValue($obj, 'available_now', $language['id_lang']), ENT_COMPAT, 'UTF-8')) . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' </td> </tr> <tr> <td class="col-left">' . $this->l('Displayed text when allowed to be back-ordered:') . '</td> <td style="padding-bottom:5px;" class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input size="30" type="text" id="available_later_' . $language['id_lang'] . '" name="available_later_' . $language['id_lang'] . '" value="' . stripslashes(htmlentities($this->getFieldValue($obj, 'available_later', $language['id_lang']), ENT_COMPAT, 'UTF-8')) . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' </td> </tr> <script type="text/javascript"> calcPriceTI(); </script> <tr> <td class="col-left">' . $this->l('When out of stock:') . '</td> <td style="padding-bottom:5px;"> <input type="radio" name="out_of_stock" id="out_of_stock_1" value="0" ' . ((int) $this->getFieldValue($obj, 'out_of_stock') == 0 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_1" class="t" id="label_out_of_stock_1">' . $this->l('Deny orders') . '</label> <br /><input type="radio" name="out_of_stock" id="out_of_stock_2" value="1" ' . ($this->getFieldValue($obj, 'out_of_stock') == 1 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_2" class="t" id="label_out_of_stock_2">' . $this->l('Allow orders') . '</label> <br /><input type="radio" name="out_of_stock" id="out_of_stock_3" value="2" ' . ($this->getFieldValue($obj, 'out_of_stock') == 2 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_3" class="t" id="label_out_of_stock_3">' . $this->l('Default:') . ' <i>' . $this->l((int) Configuration::get('PS_ORDER_OUT_OF_STOCK') ? 'Allow orders' : 'Deny orders') . '</i> (' . $this->l('as set in') . ' <a href="index.php?tab=AdminPPreferences&token=' . Tools::getAdminToken('AdminPPreferences' . (int) Tab::getIdFromClassName('AdminPPreferences') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');">' . $this->l('Preferences') . '</a>)</label> </td> </tr> <tr> <td colspan="2" style="padding-bottom:5px;"> <hr style="width:100%;" /> </td> </tr> <tr> <td class="col-left"><label for="id_category_default" class="t">' . $this->l('Default category:') . '</label></td> <td> <div id="no_default_category" style="color: red;font-weight: bold;display: none;">' . $this->l('Please check a category in order to select the default category.') . '</div> <script type="text/javascript"> var post_selected_cat; </script>'; $default_category = Tools::getValue('id_category', 1); if (!$obj->id) { $selectedCat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->_defaultFormLanguage); echo ' <script type="text/javascript"> post_selected_cat = \'' . implode(',', array_keys($selectedCat)) . '\'; </script>'; } else { if (Tools::isSubmit('categoryBox')) { $selectedCat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->_defaultFormLanguage); } else { $selectedCat = Product::getProductCategoriesFull($obj->id, $this->_defaultFormLanguage); } } echo '<select id="id_category_default" name="id_category_default">'; foreach ($selectedCat as $cat) { echo '<option value="' . $cat['id_category'] . '" ' . ($obj->id_category_default == $cat['id_category'] ? 'selected' : '') . '>' . $cat['name'] . '</option>'; } echo '</select> </td> </tr> <tr id="tr_categories"> <td colspan="2"> '; // Translations are not automatic for the moment ;) $trads = array('Home' => $this->l('Home'), 'selected' => $this->l('selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All')); echo Helper::renderAdminCategorieTree($trads, $selectedCat) . ' </td> </tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr> <tr><td colspan="2"> <span onclick="$(\'#seo\').slideToggle();" style="cursor: pointer"><img src="../img/admin/arrow.gif" alt="' . $this->l('SEO') . '" title="' . $this->l('SEO') . '" style="float:left; margin-right:5px;"/>' . $this->l('Click here to improve product\'s rank in search engines (SEO)') . '</span><br /> <div id="seo" style="display: none; padding-top: 15px;"> <table> <tr> <td class="col-left">' . $this->l('Meta title:') . '</td> <td class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="meta_title_' . $language['id_lang'] . '" name="meta_title_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_title', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear">' . $this->l('Product page title; leave blank to use product name') . '</p> </td> </tr> <tr> <td class="col-left">' . $this->l('Meta description:') . '</td> <td class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="meta_description_' . $language['id_lang'] . '" name="meta_description_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_description', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear">' . $this->l('A single sentence for HTML header') . '</p> </td> </tr> <tr> <td class="col-left">' . $this->l('Meta keywords:') . '</td> <td class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="meta_keywords_' . $language['id_lang'] . '" name="meta_keywords_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_keywords', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear">' . $this->l('Keywords for HTML header, separated by a comma') . '</p> </td> </tr> <tr> <td class="col-left">' . $this->l('Friendly URL:') . '</td> <td class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="link_rewrite_' . $language['id_lang'] . '" name="link_rewrite_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'link_rewrite', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" onkeyup="if (isArrowKey(event)) return ;updateFriendlyURL();" onchange="updateFriendlyURL();" /><sup> *</sup> <span class="hint" name="help_box">' . $this->l('Only letters and the "less" character are allowed') . '<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear" style="padding:10px 0 0 0">' . '<a style="cursor:pointer" class="button" onmousedown="updateFriendlyURLByName();">' . $this->l('Generate') . '</a> ' . $this->l('Friendly-url from product\'s name.') . '<br /><br />'; echo ' ' . $this->l('Product link will look like this:') . ' ' . (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . '/<b>id_product</b>-<span id="friendly-url"></span>.html</p> </td> </tr>'; echo '</td></tr></table> </div> </td></tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr> <tr> <td class="col-left">' . $this->l('Short description:') . '<br /><br /><i>(' . $this->l('appears in the product lists and on the top of the product page') . ')</i></td> <td style="padding-bottom:5px;" class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . ';float: left;"> <textarea class="rte" cols="100" rows="10" id="description_short_' . $language['id_lang'] . '" name="description_short_' . $language['id_lang'] . '">' . htmlentities(stripslashes($this->getFieldValue($obj, 'description_short', $language['id_lang'])), ENT_COMPAT, 'UTF-8') . '</textarea> </div>'; } echo ' </td> </tr> <tr> <td class="col-left">' . $this->l('Description:') . '<br /><br /><i>(' . $this->l('appears in the body of the product page') . ')</i></td> <td style="padding-bottom:5px;" class="translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . ';float: left;"> <textarea class="rte" cols="100" rows="20" id="description_' . $language['id_lang'] . '" name="description_' . $language['id_lang'] . '">' . htmlentities(stripslashes($this->getFieldValue($obj, 'description', $language['id_lang'])), ENT_COMPAT, 'UTF-8') . '</textarea> </div>'; } echo ' </td> </tr>'; echo ' <tr> <td class="col-left">' . $this->l('Tags:') . '</td> <td style="padding-bottom:5px;" class="translatable">'; if ($obj->id) { $obj->tags = Tag::getProductTags((int) $obj->id); } foreach ($this->_languages as $language) { echo '<div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="tags_' . $language['id_lang'] . '" name="tags_' . $language['id_lang'] . '" value="' . htmlentities(Tools::getValue('tags_' . $language['id_lang'], $obj->getTags($language['id_lang'], true)), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' !<>;?=+#"°{}_$%<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear">' . $this->l('Tags separated by commas (e.g., dvd, dvd player, hifi)') . '</p> </td> </tr>'; $accessories = Product::getAccessoriesLight((int) $cookie->id_lang, $obj->id); if ($postAccessories = Tools::getValue('inputAccessories')) { $postAccessoriesTab = explode('-', Tools::getValue('inputAccessories')); foreach ($postAccessoriesTab as $accessoryId) { if (!$this->haveThisAccessory($accessoryId, $accessories) and $accessory = Product::getAccessoryById($accessoryId)) { $accessories[] = $accessory; } } } echo ' <tr> <td class="col-left">' . $this->l('Accessories:') . '<br /><br /><i>' . $this->l('(Do not forget to Save the product afterward)') . '</i></td> <td style="padding-bottom:5px;"> <div id="divAccessories">'; foreach ($accessories as $accessory) { echo htmlentities($accessory['name'], ENT_COMPAT, 'UTF-8') . (!empty($accessory['reference']) ? ' (' . $accessory['reference'] . ')' : '') . ' <span onclick="delAccessory(' . $accessory['id_product'] . ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" class="middle" alt="" /></span><br />'; } echo '</div> <input type="hidden" name="inputAccessories" id="inputAccessories" value="'; foreach ($accessories as $accessory) { echo (int) $accessory['id_product'] . '-'; } echo '" /> <input type="hidden" name="nameAccessories" id="nameAccessories" value="'; foreach ($accessories as $accessory) { echo htmlentities($accessory['name'], ENT_COMPAT, 'UTF-8') . '¤'; } echo '" /> <script type="text/javascript"> var formProduct; var accessories = new Array(); </script> <link rel="stylesheet" type="text/css" href="' . __PS_BASE_URI__ . 'css/jquery.autocomplete.css" /> <script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/jquery/jquery.autocomplete.js"></script> <div id="ajax_choose_product" style="padding:6px; padding-top:2px; width:600px;"> <p class="clear">' . $this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:') . '</p> <input type="text" value="" id="product_autocomplete_input" /> <img onclick="$(this).prev().search();" style="cursor: pointer;" src="../img/admin/add.gif" alt="' . $this->l('Add an accessory') . '" title="' . $this->l('Add an accessory') . '" /> </div> <script type="text/javascript"> urlToCall = null; /* function autocomplete */ $(function() { $(\'#product_autocomplete_input\') .autocomplete(\'ajax_products_list.php\', { minChars: 1, autoFill: true, max:20, matchContains: true, mustMatch:true, scroll:false, cacheLength:0, formatItem: function(item) { return item[1]+\' - \'+item[0]; } }).result(addAccessory); $(\'#product_autocomplete_input\').setOptions({ extraParams: {excludeIds : getAccessorieIds()} }); }); </script> </td> </tr> <tr><td colspan="2" style="padding-bottom:10px;"><hr style="width:100%;" /></td></tr> <tr> <td colspan="2" style="text-align:center;"> <input type="submit" value="' . $this->l('Save') . '" name="submitAdd' . $this->table . '" class="button" /> <input type="submit" value="' . $this->l('Save and stay') . '" name="submitAdd' . $this->table . 'AndStay" class="button" /></td> </tr> </table> <br /> </div>'; // TinyMCE global $cookie; $iso = Language::getIsoById((int) $cookie->id_lang); $isoTinyMCE = file_exists(_PS_ROOT_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en'; $ad = dirname($_SERVER["PHP_SELF"]); echo ' <script type="text/javascript"> var iso = \'' . $isoTinyMCE . '\' ; var pathCSS = \'' . _THEME_CSS_DIR_ . '\' ; var ad = \'' . $ad . '\' ; </script> <script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/tiny_mce/tiny_mce.js"></script> <script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/tinymce.inc.js"></script> <script type="text/javascript"> toggleVirtualProduct(getE(\'is_virtual_good\')); unitPriceWithTax(\'unit\'); </script>'; $categoryBox = Tools::getValue('categoryBox', array()); }
/** * Set up the shop page with products and discounts * * @param array $product_ids The optional array of Product IDs. * Overrides any URL parameters if set * @return boolean True on success, false otherwise * @global ADONewConnection $objDatabase Database connection object * @global array $_ARRAYLANG Language array * @global array $_CONFIG Core configuration array, see {@link /config/settings.php} * @global string(?) $themesPages Themes pages(?) */ static function view_product_overview($product_ids = null) { global $_ARRAYLANG; // activate javascript shadowbox \JS::activate('shadowbox'); $flagSpecialoffer = intval(\Cx\Core\Setting\Controller\Setting::getValue('show_products_default', 'Shop')); if (isset($_REQUEST['cmd']) && $_REQUEST['cmd'] == 'discounts') { $flagSpecialoffer = Products::DEFAULT_VIEW_DISCOUNTS; } $flagLastFive = isset($_REQUEST['lastFive']); $product_id = isset($_REQUEST['productId']) ? intval($_REQUEST['productId']) : null; $cart_id = null; if (isset($_REQUEST['referer']) && $_REQUEST['referer'] == 'cart') { $cart_id = $product_id; $product_id = Cart::get_product_id($cart_id); } $manufacturer_id = isset($_REQUEST['manufacturerId']) ? intval($_REQUEST['manufacturerId']) : null; $term = isset($_REQUEST['term']) ? trim(contrexx_input2raw($_REQUEST['term'])) : null; $category_id = isset($_REQUEST['catId']) ? intval($_REQUEST['catId']) : null; if (!($product_id || $category_id || $manufacturer_id || $term || $cart_id)) { // NOTE: This is different from NULL // in that it enables listing the subcategories $category_id = 0; } // Validate parameters if ($product_id && empty($category_id)) { $objProduct = Product::getById($product_id); if ($objProduct) { $category_id = $objProduct->category_id(); } if (isset($_SESSION['shop']['previous_category_id'])) { $category_id_previous = $_SESSION['shop']['previous_category_id']; foreach (preg_split('/\\s*,\\s*/', $category_id) as $id) { if ($category_id_previous == intval($id)) { $category_id = $category_id_previous; } } } } // Remember visited Products if ($product_id) { self::rememberVisitedProducts($product_id); } $objCategory = null; if ($category_id && empty($product_id)) { $objCategory = ShopCategory::getById($category_id); if (!$objCategory) { $category_id = null; } } $shopMenu = '<form method="post" action="' . \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', '') . '">' . '<input type="text" name="term" value="' . htmlentities($term, ENT_QUOTES, CONTREXX_CHARSET) . '" style="width:150px;" /> ' . '<select name="catId" style="width:150px;">' . '<option value="0">' . $_ARRAYLANG['TXT_ALL_PRODUCT_GROUPS'] . '</option>' . ShopCategories::getMenuoptions($category_id) . '</select> ' . Manufacturer::getMenu('manufacturerId', $manufacturer_id, true) . '<input type="submit" name="bsubmit" value="' . $_ARRAYLANG['TXT_SEARCH'] . '" style="width:66px;" />' . '</form>'; self::$objTemplate->setGlobalVariable($_ARRAYLANG + array('SHOP_MENU' => $shopMenu, 'SHOP_SEARCH_TERM' => htmlentities($term, ENT_QUOTES, CONTREXX_CHARSET), 'SHOP_CATEGORIES_MENUOPTIONS' => ShopCategories::getMenuoptions($category_id, true, 0, true), 'SHOP_MANUFACTURER_MENUOPTIONS' => Manufacturer::getMenuoptions($manufacturer_id, true))); // Only show the cart info when the JS cart is not active! global $_CONFIGURATION; if (empty($_CONFIGURATION['custom']['shopJsCart'])) { self::$objTemplate->setVariable(array('SHOP_CART_INFO' => self::cart_info())); } // Exclude Category list from search results if ($term == '') { self::showCategories($category_id); } if (self::$objTemplate->blockExists('shopNextCategoryLink')) { $nextCat = ShopCategory::getNextShopCategoryId($category_id); $objCategory = ShopCategory::getById($nextCat); if ($objCategory) { self::$objTemplate->setVariable(array('SHOP_NEXT_CATEGORY_ID' => $nextCat, 'SHOP_NEXT_CATEGORY_TITLE' => str_replace('"', '"', $objCategory->name()))); } } $pagingCmd = !empty($_REQUEST['cmd']) ? '&cmd=' . contrexx_input2raw($_REQUEST['cmd']) : ''; $pagingCatId = ''; $pagingManId = ''; $pagingTerm = ''; // TODO: This probably breaks paging in search results! // Should only reset the flag conditionally, but add the URL parameters in // any case, methinks! if ($category_id > 0 && $term == '') { $flagSpecialoffer = false; $pagingCatId = "&catId={$category_id}"; } if ($manufacturer_id > 0) { $flagSpecialoffer = false; $pagingManId = "&manufacturer_id={$manufacturer_id}"; } if ($term != '') { $flagSpecialoffer = false; $pagingTerm = '&term=' . htmlentities($term, ENT_QUOTES, CONTREXX_CHARSET); } // The Product count is passed by reference and set to the total // number of records, though only as many as specified by the core // paging limit are returned in the array. $limit = \Cx\Core\Setting\Controller\Setting::getValue('numof_products_per_page_frontend', 'Shop'); //\DBG::activate(DBG_ERROR_FIREPHP); // Use Sorting class for the Product order $uri = \Html::getRelativeUri_entities(); $arrOrder = array('product.ord' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_ORD'], 'name' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_TITLE'], 'code' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_CODE'], 'price' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_PRICE'], 'id' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_DATE'], 'bestseller' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_BESTSELLER']); $defaultOrder = \Sorting::getFieldindex(Products::$arrProductOrder[\Cx\Core\Setting\Controller\Setting::getValue('product_sorting', 'Shop')]); $objSorting = new \Sorting($uri, $arrOrder, true, 'shop_order_products', $defaultOrder); //\DBG::log("Sorting headers: ".var_export($objSorting->getHeaderArray(), true)); $count = $limit; $arrProduct = array(); if ($product_ids) { $arrProduct = self::getValidProducts($product_ids); $product_id = null; // Suppress meta title from single Product } elseif ($product_id) { $arrProduct = self::getValidProducts(array($product_id)); } else { $arrProduct = Products::getByShopParams($count, \Paging::getPosition(), $product_id, $category_id, $manufacturer_id, $term, $flagSpecialoffer, $flagLastFive, $objSorting->getOrder(), self::$objCustomer && self::$objCustomer->is_reseller()); } // Only show sorting when there's enough to be sorted if ($count > 1) { $objSorting->parseHeaders(self::$objTemplate, 'shop_product_order'); } if ($count == 0 && !ShopCategories::getChildCategoryIdArray($category_id)) { //if ($term != '' || $manufacturer_id != 0 || $flagSpecialoffer) { if (self::$objTemplate->blockExists('no_product')) { self::$objTemplate->touchBlock('no_product'); } return true; } if ($objCategory) { // Only indicate the category name when there are products if ($count) { self::$objTemplate->setVariable(array('SHOP_CATEGORY_CURRENT_NAME' => contrexx_raw2xhtml($objCategory->name()), 'SHOP_PRODUCTS_IN_CATEGORY' => sprintf($_ARRAYLANG['TXT_SHOP_PRODUCTS_IN_CATEGORY'], contrexx_raw2xhtml($objCategory->name())))); } } else { // TODO: There are other cases of flag combinations that are not indivuidually // handled here yet. if ($term == '') { if ($flagSpecialoffer == Products::DEFAULT_VIEW_DISCOUNTS) { self::$objTemplate->setVariable('SHOP_PRODUCTS_IN_CATEGORY', $_ARRAYLANG['TXT_SHOP_PRODUCTS_SPECIAL_OFFER']); } else { if (self::$objTemplate->blockExists('products_in_category')) { self::$objTemplate->hideBlock('products_in_category'); } } } else { self::$objTemplate->setVariable('SHOP_PRODUCTS_IN_CATEGORY', sprintf($_ARRAYLANG['TXT_SHOP_PRODUCTS_SEARCH_RESULTS'], contrexx_raw2xhtml($term))); } } $uri = '&section=Shop' . MODULE_INDEX . $pagingCmd . $pagingCatId . $pagingManId . $pagingTerm; self::$objTemplate->setVariable(array('SHOP_PRODUCT_PAGING' => \Paging::get($uri, '', $count, $limit, $count > 0), 'SHOP_PRODUCT_TOTAL' => $count)); // Global microdata: Seller information $seller_url = \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', '')->toString(); $seller_name = \Cx\Core\Setting\Controller\Setting::getValue('company', 'Shop'); if (empty($seller_name)) { $seller_name = $seller_url; } self::$objTemplate->setVariable(array('SHOP_SELLER_NAME' => $seller_name, 'SHOP_SELLER_URL' => $seller_url)); $formId = 0; $arrDefaultImageSize = $arrSize = null; foreach ($arrProduct as $objProduct) { if (!empty($product_id)) { self::$pageTitle = $objProduct->name(); } $id = $objProduct->id(); $productSubmitFunction = ''; $arrPictures = Products::get_image_array_from_base64($objProduct->pictures()); $havePicture = false; $arrProductImages = array(); foreach ($arrPictures as $index => $image) { $thumbnailPath = $pictureLink = ''; if (empty($image['img']) || $image['img'] == ShopLibrary::noPictureName) { // We have at least one picture on display already. // No need to show "no picture" three times! if ($havePicture) { continue; } $thumbnailPath = self::$defaultImage; $pictureLink = '#'; //"javascript:alert('".$_ARRAYLANG['TXT_NO_PICTURE_AVAILABLE']."');"; if (empty($arrDefaultImageSize)) { $arrDefaultImageSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . self::$defaultImage); self::scaleImageSizeToThumbnail($arrDefaultImageSize); } $arrSize = $arrDefaultImageSize; } else { $thumbnailPath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . \ImageManager::getThumbnailFilename($image['img']); if ($image['width'] && $image['height']) { $pictureLink = contrexx_raw2encodedUrl(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . $image['img']) . '" rel="shadowbox[' . ($formId + 1) . ']'; // Thumbnail display size $arrSize = array($image['width'], $image['height']); } else { $pictureLink = '#'; if (!file_exists(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . $thumbnailPath)) { continue; } $arrSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . $thumbnailPath); } self::scaleImageSizeToThumbnail($arrSize); // Use the first available picture in microdata, if any if (!$havePicture) { $picture_url = \Cx\Core\Routing\Url::fromCapturedRequest(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . $image['img'], \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteOffsetPath(), array()); self::$objTemplate->setVariable('SHOP_PRODUCT_IMAGE', $picture_url->toString()); //\DBG::log("Set image to ".$picture_url->toString()); } } $arrProductImages[] = array('THUMBNAIL' => contrexx_raw2encodedUrl($thumbnailPath), 'THUMBNAIL_SIZE' => $arrSize[3], 'THUMBNAIL_LINK' => $pictureLink, 'POPUP_LINK' => $pictureLink, 'POPUP_LINK_NAME' => $_ARRAYLANG['TXT_SHOP_IMAGE'] . ' ' . $index); $havePicture = true; } $i = 1; foreach ($arrProductImages as $arrProductImage) { // TODO: Instead of several numbered image blocks, use a single one repeatedly self::$objTemplate->setVariable(array('SHOP_PRODUCT_THUMBNAIL_' . $i => $arrProductImage['THUMBNAIL'], 'SHOP_PRODUCT_THUMBNAIL_SIZE_' . $i => $arrProductImage['THUMBNAIL_SIZE'])); if (!empty($arrProductImage['THUMBNAIL_LINK'])) { self::$objTemplate->setVariable(array('SHOP_PRODUCT_THUMBNAIL_LINK_' . $i => $arrProductImage['THUMBNAIL_LINK'], 'TXT_SEE_LARGE_PICTURE' => $_ARRAYLANG['TXT_SEE_LARGE_PICTURE'])); } else { self::$objTemplate->setVariable('TXT_SEE_LARGE_PICTURE', contrexx_raw2xhtml($objProduct->name())); } if ($arrProductImage['POPUP_LINK']) { self::$objTemplate->setVariable('SHOP_PRODUCT_POPUP_LINK_' . $i, $arrProductImage['POPUP_LINK']); } self::$objTemplate->setVariable('SHOP_PRODUCT_POPUP_LINK_NAME_' . $i, $arrProductImage['POPUP_LINK_NAME']); ++$i; } $stock = $objProduct->stock_visible() ? $_ARRAYLANG['TXT_STOCK'] . ': ' . intval($objProduct->stock()) : ''; $price = $objProduct->get_custom_price(self::$objCustomer, 0, 1, true); // If there is a discountprice and it's enabled $discountPrice = ''; if ($objProduct->discountprice() > 0 && $objProduct->discount_active()) { $price = '<s>' . $price . '</s>'; $discountPrice = $objProduct->get_custom_price(self::$objCustomer, 0, 1, false); } $groupCountId = $objProduct->group_id(); $groupArticleId = $objProduct->article_id(); $groupCustomerId = 0; if (self::$objCustomer) { $groupCustomerId = self::$objCustomer->group_id(); } self::showDiscountInfo($groupCustomerId, $groupArticleId, $groupCountId, 1); /* OLD $price = Currency::getCurrencyPrice( $objProduct->getCustomerPrice(self::$objCustomer) ); $discountPrice = ''; $discount_active = $objProduct->discount_active(); if ($discount_active) { $discountPrice = $objProduct->discountprice(); if ($discountPrice > 0) { $price = "<s>$price</s>"; $discountPrice = Currency::getCurrencyPrice($discountPrice); } } */ $short = $objProduct->short(); $longDescription = $objProduct->long(); $detailLink = null; // Detaillink is required for microdata (even when longdesc // is empty) $detail_url = \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'details', FRONTEND_LANG_ID, array('productId' => $objProduct->id()))->toString(); self::$objTemplate->setVariable('SHOP_PRODUCT_DETAIL_URL', $detail_url); if (!$product_id && !empty($longDescription)) { $detailLink = '<a href="' . $detail_url . '"' . ' title="' . $_ARRAYLANG['TXT_MORE_INFORMATIONS'] . '">' . $_ARRAYLANG['TXT_MORE_INFORMATIONS'] . '</a>'; self::$objTemplate->setVariable('SHOP_PRODUCT_DETAILLINK', $detailLink); } // Check Product flags. // Only the meter flag is currently implemented and in use. $flagMeter = $objProduct->testFlag('__METER__'); // Submit button name and function. // Calling productOptions() also sets the $flagMultipart variable // to the appropriate encoding type for the form if // any upload fields are in use. $flagMultipart = false; $productSubmitName = $productSubmitFunction = ''; if (isset($_GET['cmd']) && $_GET['cmd'] == 'details' && isset($_GET['referer']) && $_GET['referer'] == 'cart') { $productSubmitName = "updateProduct[{$cart_id}]"; $productSubmitFunction = self::productOptions($id, $formId, $cart_id, $flagMultipart); } else { $productSubmitName = 'addProduct'; $productSubmitFunction = self::productOptions($id, $formId, $cart_id, $flagMultipart); } $shopProductFormName = "shopProductForm{$formId}"; $row = $formId % 2 + 1; self::$objTemplate->setVariable(array('SHOP_ROWCLASS' => 'row' . $row, 'SHOP_PRODUCT_ID' => $objProduct->id(), 'SHOP_PRODUCT_TITLE' => contrexx_raw2xhtml($objProduct->name()), 'SHOP_PRODUCT_DESCRIPTION' => $short, 'SHOP_PRODUCT_DETAILDESCRIPTION' => $longDescription ? $longDescription : $short, 'SHOP_PRODUCT_FORM_NAME' => $shopProductFormName, 'SHOP_PRODUCT_SUBMIT_NAME' => $productSubmitName, 'SHOP_PRODUCT_SUBMIT_FUNCTION' => $productSubmitFunction, 'SHOP_FORM_ENCTYPE' => $flagMultipart ? ' enctype="multipart/form-data"' : '', 'TXT_SHOP_PRODUCT_COUNT' => $flagMeter ? $_ARRAYLANG['TXT_SHOP_PRODUCT_METER'] : $_ARRAYLANG['TXT_SHOP_PRODUCT_COUNT'], 'SHOP_CURRENCY_CODE' => Currency::getActiveCurrencyCode())); if ($objProduct->code()) { self::$objTemplate->setVariable('SHOP_PRODUCT_CUSTOM_ID', htmlentities($objProduct->code(), ENT_QUOTES, CONTREXX_CHARSET)); } $manufacturer_name = $manufacturer_url = $manufacturer_link = ''; $manufacturer_id = $objProduct->manufacturer_id(); if ($manufacturer_id) { $manufacturer_name = Manufacturer::getNameById($manufacturer_id, FRONTEND_LANG_ID); $manufacturer_url = Manufacturer::getUrlById($manufacturer_id, FRONTEND_LANG_ID); } if (!empty($manufacturer_url) || !empty($manufacturer_name)) { if (empty($manufacturer_name)) { $manufacturer_name = $manufacturer_url; } if (!empty($manufacturer_url)) { $manufacturer_link = '<a href="' . $manufacturer_url . '">' . $manufacturer_name . '</a>'; } // TODO: Test results for any combination of name and url self::$objTemplate->setVariable(array('SHOP_MANUFACTURER_NAME' => $manufacturer_name, 'SHOP_MANUFACTURER_URL' => $manufacturer_url, 'SHOP_MANUFACTURER_LINK' => $manufacturer_link, 'TXT_SHOP_MANUFACTURER_LINK' => $_ARRAYLANG['TXT_SHOP_MANUFACTURER_LINK'])); } // This is the old Product field for the Manufacturer URI. // This is now extended by the Manufacturer table and should thus // get a new purpose. As it is product specific, it could be // renamed and reused as a link to individual Products! $externalLink = $objProduct->uri(); if (!empty($externalLink)) { self::$objTemplate->setVariable(array('SHOP_EXTERNAL_LINK' => '<a href="' . $externalLink . '" title="' . $_ARRAYLANG['TXT_SHOP_EXTERNAL_LINK'] . '" target="_blank">' . $_ARRAYLANG['TXT_SHOP_EXTERNAL_LINK'] . '</a>')); } if ($price) { self::$objTemplate->setGlobalVariable(array('SHOP_PRODUCT_PRICE' => $price, 'SHOP_PRODUCT_PRICE_UNIT' => Currency::getActiveCurrencySymbol())); } // Only show the discount price if it's actually in use, // avoid an "empty <font> tag" HTML warning if ($discountPrice) { self::$objTemplate->setGlobalVariable(array('SHOP_PRODUCT_DISCOUNTPRICE' => $discountPrice, 'SHOP_PRODUCT_DISCOUNTPRICE_UNIT' => Currency::getActiveCurrencySymbol())); if (self::$objTemplate->blockExists('price_discount')) { self::$objTemplate->touchBlock('price_discount'); } } else { if (self::$objTemplate->blockExists('price')) { self::$objTemplate->touchBlock('price'); } } // Special outlet ShopCategory with discounts varying daily. // This should be implemented in a more generic way, in the // Discount class maybe. if ($objProduct->is_outlet()) { self::$objTemplate->setVariable(array('TXT_SHOP_DISCOUNT_TODAY' => $_ARRAYLANG['TXT_SHOP_DISCOUNT_TODAY'], 'SHOP_DISCOUNT_TODAY' => $objProduct->getOutletDiscountRate() . '%', 'TXT_SHOP_PRICE_TODAY' => $_ARRAYLANG['TXT_SHOP_PRICE_TODAY'], 'SHOP_PRICE_TODAY' => Currency::getCurrencyPrice($objProduct->getDiscountedPrice()), 'SHOP_PRICE_TODAY_UNIT' => Currency::getActiveCurrencySymbol())); } if ($objProduct->stock_visible()) { self::$objTemplate->setVariable(array('SHOP_PRODUCT_STOCK' => $stock)); } if ($detailLink) { self::$objTemplate->setVariable(array('SHOP_PRODUCT_DETAILLINK' => $detailLink)); } $distribution = $objProduct->distribution(); $weight = ''; if ($distribution == 'delivery') { $weight = $objProduct->weight(); } // Hide the weight if it is zero or disabled in the configuration if ($weight > 0 && \Cx\Core\Setting\Controller\Setting::getValue('weight_enable', 'Shop')) { self::$objTemplate->setVariable(array('TXT_SHOP_PRODUCT_WEIGHT' => $_ARRAYLANG['TXT_SHOP_PRODUCT_WEIGHT'], 'SHOP_PRODUCT_WEIGHT' => Weight::getWeightString($weight))); } if (Vat::isEnabled()) { self::$objTemplate->setVariable(array('SHOP_PRODUCT_TAX_PREFIX' => Vat::isIncluded() ? $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_INCL'] : $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_EXCL'], 'SHOP_PRODUCT_TAX' => Vat::getShort($objProduct->vat_id()))); } // Add flag images for flagged Products $strImage = ''; $strFlags = $objProduct->flags(); $arrVirtual = ShopCategories::getVirtualCategoryNameArray(FRONTEND_LANG_ID); foreach (explode(' ', $strFlags) as $strFlag) { if (in_array($strFlag, $arrVirtual)) { $strImage .= '<img src="images/content/' . $strFlag . '.jpg" alt="' . $strFlag . '" />'; } } if ($strImage) { self::$objTemplate->setVariable('SHOP_PRODUCT_FLAG_IMAGE', $strImage); } $minimum_order_quantity = $objProduct->minimum_order_quantity(); //Activate Quantity-Inputfield when minimum_order_quantity exists if (self::$objTemplate->blockExists('orderQuantity') && $minimum_order_quantity > 0) { self::$objTemplate->setVariable('SHOP_PRODUCT_MINIMUM_ORDER_QUANTITY', contrexx_raw2xhtml($objProduct->minimum_order_quantity())); } elseif (self::$objTemplate->blockExists('orderQuantity') && !$minimum_order_quantity) { self::$objTemplate->hideBlock('orderQuantity'); } if (self::$objTemplate->blockExists('shopProductRow')) { self::$objTemplate->parse('shopProductRow'); } ++$formId; } return true; }
protected function renderCatalog() { $stckmgtfr = ERP_STCKMGTFR; if (Tools::isSubmit('export_catalog')) { //OUPUT HEADERS header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=catalog_' . date('Y-m-d_His') . '.csv;'); header('Content-Transfer-Encoding: binary'); $id_warehouse = (int) Tools::getValue('id_warehouse'); $area = (int) Tools::getValue('area'); $subarea = (int) Tools::getValue('subarea'); // GET COMBINATIONS $combination = new DbQuery(); $select_combination = 'pa.id_product, pa.id_product_attribute, pa.reference, pa.ean13, IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(DISTINCT agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as name, p.price as price_product, pa.price as price_attribute, p.id_tax_rules_group, p.id_manufacturer, cl.name as category, CASE pa.wholesale_price WHEN 0.000000 THEN p.wholesale_price ELSE pa.wholesale_price END as wholesale_price, IFNULL( pa.weight, p.weight) as weight, pl.description, pl.description_short '; // get product and product attribute of selected warehouse if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != "-1") { $select_combination .= ', wpl.location, z.name as area, sz.name as subarea'; $combination->innerjoin('warehouse_product_location', 'wpl', 'wpl.id_warehouse = ' . $id_warehouse . ' ' . 'AND pa.id_product = wpl.id_product AND wpl.id_product_attribute = IFNULL(pa.id_product_attribute, 0)'); $combination->leftjoin('erpip_warehouse_product_location', 'ewpl', '(wpl.id_warehouse_product_location = ewpl.id_warehouse_product_location)'); $combination->leftjoin('erpip_zone', 'z', '(z.id_erpip_zone = ewpl.id_zone_parent)'); $combination->leftjoin('erpip_zone', 'sz', '(sz.id_erpip_zone = ewpl.id_zone)'); // filter on area if ($area != null && $subarea == null) { $combination->where('z.id_erpip_zone = ' . (int) $area); } // filter on area and sub area if ($area != null && $subarea != null) { $combination->where('z.id_erpip_zone = ' . (int) $area); $combination->where('sz.id_erpip_zone = ' . (int) $subarea); } } $combination->select($select_combination); $combination->from('product_attribute', 'pa'); $combination->innerjoin('product', 'p', 'pa.id_product = p.id_product'); $combination->innerjoin('product_lang', 'pl', 'pa.id_product = pl.id_product'); $combination->innerjoin('product_attribute_combination', 'pac', 'pac.id_product_attribute = pa.id_product_attribute'); $combination->innerjoin('attribute', 'atr', 'atr.id_attribute = pac.id_attribute'); $combination->innerjoin('attribute_lang', 'al', 'al.id_attribute = pac.id_attribute AND al.id_lang=' . (int) $this->context->language->id); $combination->innerjoin('attribute_group_lang', 'agl', 'agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang=' . (int) $this->context->language->id); $combination->innerjoin('category_lang', 'cl', 'cl.id_category = p.id_category_default AND cl.id_lang =' . (int) $this->context->language->id); $combination->groupBy('pa.id_product, pa.id_product_attribute'); if ($this->controller_status == STATUS1) { $combination->limit($stckmgtfr); $this->informations[] = sprintf($this->l('You are using the free version of 1-Click ERP which limits document editing to %d products'), $order_free_limit); } $combinations = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($combination); // list of product ids $ids = array(); foreach ($combinations as $combination) { $ids[] = (int) $combination['id_product']; } $ids = array_unique($ids); // GET PRODUCT WITHOUT COMBINATIONS $product = new DbQuery(); // Base query $select_product = 'p.id_product, p.reference, p.ean13, pl.name as name, p.weight, pl.description, pl.description_short, p.price as price_product, p.id_tax_rules_group, p.id_manufacturer, cl.name as category, p.wholesale_price as wholesale_price'; // warehouse query if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != "-1") { $select_product .= ', wpl.location, z.name as area, sz.name as subarea'; $product->innerjoin('warehouse_product_location', 'wpl', 'wpl.id_warehouse = ' . $id_warehouse . ' AND p.id_product = wpl.id_product AND wpl.id_product_attribute = 0'); $product->leftjoin('erpip_warehouse_product_location', 'ewpl', '(wpl.id_warehouse_product_location = ewpl.id_warehouse_product_location)'); $product->leftjoin('erpip_zone', 'z', '(z.id_erpip_zone = ewpl.id_zone_parent)'); $product->leftjoin('erpip_zone', 'sz', '(sz.id_erpip_zone = ewpl.id_zone)'); // filter on area if ($area != null && $subarea == null) { $product->where('z.id_erpip_zone = ' . (int) $area); } // filter on area and sub area if ($area != null && $subarea != null) { $product->where('z.id_erpip_zone = ' . (int) $area); $product->where('sz.id_erpip_zone = ' . (int) $subarea); } } $product->select($select_product); $product->from('product', 'p'); $product->innerjoin('product_lang', 'pl', 'p.id_product = pl.id_product'); $product->innerjoin('category_lang', 'cl', 'cl.id_category = p.id_category_default AND cl.id_lang =' . (int) $this->context->language->id); // if we have attributes we filter for not having a product already listed with attributes if (count($ids) > 0) { $product->where('p.id_product NOT IN (' . pSQL(implode(',', array_map('intval', $ids))) . ') '); } $product->groupBy('p.id_product'); if ($this->controller_status == STATUS1) { $product->limit($stckmgtfr); $this->informations[] = sprintf($this->l('You are using the free version of 1-Click ERP which limits document editing to %d products'), $order_free_limit); } $products = Db::getInstance()->executeS($product); // merge product with product attribute $query = array_merge($products, $combinations); if ($this->controller_status == STATUS1) { $query = array_splice($query, 0, $stckmgtfr); } $nb_items = count($query); for ($i = 0; $i < $nb_items; ++$i) { $item =& $query[$i]; // gets stock manager $manager = StockManagerFactory::getManager(); // id_product_attribute pour un produit sans déclinaisons if (!isset($item['id_product_attribute'])) { $item['id_product_attribute'] = 0; } // gets quantities and valuation $stock = new DbQuery(); $stock->select('SUM(physical_quantity) as physical_quantity'); $stock->select('SUM(usable_quantity) as usable_quantity'); $stock->select('SUM(price_te * physical_quantity) as valuation'); $stock->from('stock'); if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != "-1") { $stock->where('id_product =' . (int) $item['id_product'] . ' AND id_product_attribute = ' . (int) $item['id_product_attribute'] . ' AND id_warehouse = ' . (int) $id_warehouse); } else { $stock->where('id_product =' . (int) $item['id_product'] . ' AND id_product_attribute = ' . (int) $item['id_product_attribute']); } $res_stock = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($stock); $item['physical_quantity'] = $res_stock['physical_quantity']; // real quantity if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != "-1") { $item['real_quantity'] = $manager->getProductRealQuantities($item['id_product'], $item['id_product_attribute'], $id_warehouse, true); } else { $item['real_quantity'] = $manager->getProductRealQuantities($item['id_product'], $item['id_product_attribute'], null, true); } // price tax include and tax $price = new DbQuery(); $price->select('rate'); $price->from('tax', 't'); $price->innerjoin('tax_rule', 'tr', 'tr.id_tax = t.id_tax'); $price->where('t.id_tax = ' . (int) $item['id_tax_rules_group']); $price->where('tr.id_country = ' . (int) $this->context->country->id); $res_price = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($price); $item['rate'] = $res_price['rate']; // if we are in product if (!isset($item['price_attribute'])) { $item['price_ttc'] = $item['price_product'] * ($res_price['rate'] / 100) + $item['price_product']; } else { $price = $item['price_product'] + $item['price_attribute']; $item['price_ttc'] = $price * ($res_price['rate'] / 100) + $price; } // get manufacturer $item['manufacturer'] = Manufacturer::getNameById($item['id_manufacturer']); // get image product id $id_image = Product::getCover((int) $item['id_product']); // there is an image ? if ($id_image != false) { $image = new Image($id_image['id_image']); $item['url_image'] = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . ".jpg"; } else { $item['url_image'] = $this->l('No image'); } } // BASE CSV HEADER $header = array($this->l('PRODUCT_ID_'), $this->l('PRODUCT_ATTRIBUTE_ID'), $this->l('SKU'), $this->l('EAN13'), $this->l('MANUFACTURER'), $this->l('CATEGORY'), $this->l('PRODUCT_NAME'), $this->l('PRODUCT_WEIGHT'), $this->l('DESCRIPTION'), $this->l('DESCRIPTION_SHORT'), $this->l('URL_IMAGE'), $this->l('PHYSICAL_QTE'), $this->l('REAL_QTY'), $this->l('PURCHASE_PRICE'), $this->l('PRICES_TAX_EXCL'), $this->l('PRICES_TAX_INCL'), $this->l('VAT_RATE')); // CSV WITH WAREHOUSE LOCATION if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != "-1") { if ($area != null && $subarea == null) { array_push($header, $this->l('AREA')); } // filter on area and sub area if ($area != null && $subarea != null) { array_push($header, $this->l('AREA'), $this->l('SUBAREA')); } array_push($header, $this->l('LOCATION')); } // Print header echo implode(';', $header) . "\r\n"; // generate CSV file foreach ($query as $product) { if (!isset($product['price_attribute'])) { $product['price_attribute'] = 0; } $content = array($product['id_product'], $product['id_product_attribute'], $product['reference'], $product['ean13'], $product['manufacturer'], self::transformText($product['category']), self::transformText($product['name']), $product['weight'], self::transformText($product['description']), self::transformText($product['description_short']), self::transformText($product['url_image']), $product['physical_quantity'], $product['real_quantity'], round($product['wholesale_price'], 2), round($product['price_product'] + $product['price_attribute'], 2), round($product['price_ttc'], 2), round($product['rate'], 2)); if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != "-1") { if ($area != null && $subarea == null) { array_push($content, $product['area']); } // filter on area and sub area if ($area != null && $subarea != null) { array_push($content, $product['area'], $product['subarea']); } array_push($content, $product['location']); } echo implode(';', $content) . "\r\n"; } echo sprintf($this->l('You are using the free version of 1-Click ERP which limits the export to %d products'), $stckmgtfr); die; } }
function displayFormInformations($obj, $currency, $languages, $defaultLanguage) { global $currentIndex, $cookie; $iso = Language::getIsoById(intval($cookie->id_lang)); $divLangName = 'cname¤cdesc¤cdesc_short¤clink_rewrite¤cmeta_description¤cmeta_title¤cmeta_keywords¤ctags¤cavailable_now¤cavailable_later'; $qty_state = 'readonly'; $qty = Attribute::getAttributeQty($this->getFieldValue($obj, 'id_product')); if ($qty === false) { if (Validate::isLoadedObject($obj)) { $qty = $this->getFieldValue($obj, 'quantity'); } else { $qty = 1; } $qty_state = ''; } $cover = Product::getCover($obj->id); $link = new Link(); //includeDatepicker(array('reduction_from', 'reduction_to')); echo ' <div class="tab-page" id="step1"> <h4 class="tab">1. ' . $this->l('Info.') . '</h4> <b>' . $this->l('Product global informations') . '</b> - '; if (isset($obj->id)) { echo ' <a href="' . $link->getProductLink($this->getFieldValue($obj, 'id'), $this->getFieldValue($obj, 'link_rewrite', $defaultLanguage), Category::getLinkRewrite($this->getFieldValue($obj, 'id_category_default'), intval($cookie->id_lang))) . '"><img src="../img/admin/details.gif" alt="' . $this->l('View product in shop') . '" title="' . $this->l('View product in shop') . '" /> ' . $this->l('View product in shop') . '</a>'; if (file_exists(_PS_MODULE_DIR_ . 'statsproduct/statsproduct.php')) { echo ' - <a href="index.php?tab=AdminStatsModules&module=statsproduct&id_product=' . $obj->id . '&token=' . Tools::getAdminToken('AdminStatsModules' . intval(Tab::getIdFromClassName('AdminStatsModules')) . intval($cookie->id_employee)) . '"><img src="../modules/statsproduct/logo.gif" alt="' . $this->l('View product sales') . '" title="' . $this->l('View product sales') . '" /> ' . $this->l('View product sales') . '</a>'; } } echo ' <hr class="clear"/> <br /> <table cellpadding="5" style="width:100%"> <tr> <td class="col-left">' . $this->l('Name:') . '</td> <td style="padding-bottom:5px;">'; foreach ($languages as $language) { echo ' <div id="cname_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="name_' . $language['id_lang'] . '" name="name_' . $language['id_lang'] . '" value="' . stripslashes(htmlspecialchars($this->getFieldValue($obj, 'name', $language['id_lang']))) . '"' . (!$obj->id ? ' onkeyup="copy2friendlyURL();"' : '') . ' onchange="updateCurrentText();" /><sup> *</sup> <span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cname'); echo '<script type="text/javascript">updateCurrentText();</script> </td> </tr> <tr> <td style="vertical-align:top">' . $this->l('Status:') . '</td> <td style="padding-bottom:5px;"> <input style="float:left;" type="radio" name="active" id="active_on" value="1" ' . ($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/> <label for="active_on" class="t"><img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" style="float:left; padding:0px 5px 0px 5px;" />' . $this->l('Enabled') . '</label> <br style="clear:both;" /> <input style="float:left;" type="radio" name="active" id="active_off" value="0" ' . (!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/> <label for="active_off" class="t"><img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" style="float:left; padding:0px 5px 0px 5px" />' . $this->l('Disabled') . '</label> </td> </tr> <tr> <td>' . $this->l('Manufacturer:') . '</td> <td style="padding-bottom:5px;"> <select name="id_manufacturer" id="id_manufacturer"> <option value="0">-- ' . $this->l('Choose (optional)') . ' --</option>'; if ($id_manufacturer = $this->getFieldValue($obj, 'id_manufacturer')) { echo ' <option value="' . $id_manufacturer . '" selected="selected">' . Manufacturer::getNameById($id_manufacturer) . '</option> <option disabled="disabled">----------</option>'; } echo ' </select> <a href="?tab=AdminManufacturers&addmanufacturer&token=' . Tools::getAdminToken('AdminManufacturers' . intval(Tab::getIdFromClassName('AdminManufacturers')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/add.gif" alt="' . $this->l('Create') . '" title="' . $this->l('Create') . '" /> <b>' . $this->l('Create') . '</b></a> <script type="text/javascript"> var ajaxManufacturersClicked = false; $("select#id_manufacturer").focus( function() { if (ajaxManufacturersClicked == true) return; else ajaxManufacturersClicked = true; $.getJSON("' . dirname($currentIndex) . '/ajax.php",{ajaxProductManufacturers:1}, function(j) { var options = \'\'; for (var i = 0; i < getE("id_manufacturer").options.length; i++) { if (getE("id_manufacturer").options[i].innerHTML == \'----------\') options += \'<option disabled="disabled">----------</option>\'; else options += \'<option value="\' + getE("id_manufacturer").options[i].value + \'">\' + getE("id_manufacturer").options[i].innerHTML + \'</option>\'; } for (var i = 0; i < j.length; i++) options += \'<option value="\' + j[i].optionValue + \'">\' + j[i].optionDisplay + \'</option>\'; $("select#id_manufacturer").html(options); } ) } ); </script> </td> </tr> <tr> <td>' . $this->l('Supplier:') . '</td> <td style="padding-bottom:5px;"> <select name="id_supplier" id="id_supplier"> <option value="0">-- ' . $this->l('Choose (optional)') . ' --</option>'; if ($id_supplier = $this->getFieldValue($obj, 'id_supplier')) { echo ' <option value="' . $id_supplier . '" selected="selected">' . Supplier::getNameById($id_supplier) . '</option> <option disabled="disabled">----------</option>'; } echo ' </select> <a href="?tab=AdminSuppliers&addsupplier&token=' . Tools::getAdminToken('AdminSuppliers' . intval(Tab::getIdFromClassName('AdminSuppliers')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/add.gif" alt="' . $this->l('Create') . '" title="' . $this->l('Create') . '" /> <b>' . $this->l('Create') . '</b></a> <script type="text/javascript"> var ajaxSuppliersClicked = false; $("select#id_supplier").focus( function() { if (ajaxSuppliersClicked == true) return; else ajaxSuppliersClicked = true; $.getJSON("' . dirname($currentIndex) . '/ajax.php",{ajaxProductSuppliers:1}, function(j) { var options = \'\'; for (var i = 0; i < getE("id_supplier").options.length; i++) { if (getE("id_supplier").options[i].innerHTML == \'----------\') options += \'<option disabled="disabled">----------</option>\'; else options += \'<option value="\' + getE("id_supplier").options[i].value + \'">\' + getE("id_supplier").options[i].innerHTML + \'</option>\'; } for (var i = 0; i < j.length; i++) options += \'<option value="\' + j[i].optionValue + \'">\' + j[i].optionDisplay + \'</option>\'; $("select#id_supplier").html(options); } ) } ); </script> </td> </tr> <tr> <td class="col-left">' . $this->l('Reference:') . '</td> <td style="padding-bottom:5px;"> <input size="55" type="text" name="reference" value="' . htmlentities($this->getFieldValue($obj, 'reference'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 44px;" /> ' . $this->l('EAN13:') . '<input size="55" maxlength="13" type="text" name="ean13" value="' . $this->getFieldValue($obj, 'ean13') . '" style="width: 110px; margin-left: 10px;" /> <span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#\\<span class="hint-pointer"> </span></span> </td> </tr> <tr> <td class="col-left">' . $this->l('Supplier Reference:') . '</td> <td style="padding-bottom:5px;"> <input size="55" type="text" name="supplier_reference" value="' . htmlentities($this->getFieldValue($obj, 'supplier_reference'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 44px;" /> ' . $this->l('Location:') . '<input size="55" type="text" name="location" value="' . $this->getFieldValue($obj, 'location') . '" style="width: 101px; margin-left: 10px;" /> <span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#\\<span class="hint-pointer"> </span></span> </td> </tr> <tr> <td class="col-left">' . $this->l('Weight:') . '</td> <td style="padding-bottom:5px;"> <input size="6" maxlength="6" name="weight" type="text" value="' . htmlentities($this->getFieldValue($obj, 'weight'), ENT_COMPAT, 'UTF-8') . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_WEIGHT_UNIT') . ' </td> </tr> <tr><td colspan="2"><hr style="width:730px;"></td></tr>'; $this->displayPack($obj); echo ' <tr><td colspan="2"><hr style="width:730px;"></td></tr>'; /* * Form for add a virtual product like software, mp3, etc... */ $productDownload = new ProductDownload(); if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($obj, 'id'))) { $productDownload = new ProductDownload($id_product_download); } ?> <script type="text/javascript"> // <![CDATA[ ThickboxI18nImage = '<?php echo $this->l('Image'); ?> '; ThickboxI18nOf = '<?php echo $this->l('of'); ?> ';; ThickboxI18nClose = '<?php echo $this->l('Close'); ?> '; ThickboxI18nOrEscKey = '<?php echo $this->l('(or "Esc")'); ?> '; ThickboxI18nNext = '<?php echo $this->l('Next >'); ?> '; ThickboxI18nPrev = '<?php echo $this->l('< Previous'); ?> '; tb_pathToImage = '../img/loadingAnimation.gif'; //]]> </script> <script type="text/javascript" src="<?php echo _PS_JS_DIR_; ?> jquery/thickbox-modified.js"></script> <script type="text/javascript" src="<?php echo _PS_JS_DIR_; ?> jquery/ajaxfileupload.js"></script> <script type="text/javascript" src="<?php echo _PS_JS_DIR_; ?> date.js"></script> <style type="text/css"> <!-- @import url(<?php echo _PS_CSS_DIR_; ?> thickbox.css); --> </style> <script type="text/javascript"> <!-- function toggleVirtualProduct(elt) { if (elt.checked) { $('#virtual_good').show('slow'); getE('out_of_stock_1').checked = 'checked'; getE('out_of_stock_2').readOnly = true; getE('out_of_stock_3').readOnly = true; getE('label_out_of_stock_2').setAttribute('for', ''); getE('label_out_of_stock_3').setAttribute('for', ''); } else { $('#virtual_good').hide('slow'); getE('out_of_stock_2').readOnly = false; getE('out_of_stock_3').readOnly = false; getE('label_out_of_stock_2').setAttribute('for', 'out_of_stock_2'); getE('label_out_of_stock_3').setAttribute('for', 'out_of_stock_3'); } } function uploadFile() { $.ajaxFileUpload ( { url:'./uploadProductFile.php', secureuri:false, fileElementId:'virtual_product_file', dataType: 'xml', success: function (data, status) { data = data.getElementsByTagName('return')[0]; var result = data.getAttribute("result"); var msg = data.getAttribute("msg"); var fileName = data.getAttribute("filename"); if(result == "error") { $("#upload-confirmation").html('<p>error: ' + msg + '</p>'); } else { $('#virtual_product_file').remove(); $('#virtual_product_file_label').hide(); $('#virtual_product_name').attr('value', fileName); $('#upload-confirmation').html( '<a class="link" href="get-file-admin.php?file=' + msg + '"><?php echo $this->l('The file'); ?> "' + fileName + '" <?php echo $this->l('has successfully been uploaded'); ?> </a>' + '<input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="' + msg + '" />'); } } } ); } --> </script> <?php echo ' <script type="text/javascript"> var newLabel = \'' . $this->l('New label') . '\'; var choose_language = \'' . $this->l('Choose language:') . '\'; var required = \'' . $this->l('required') . '\'; var customizationUploadableFileNumber = ' . intval($this->getFieldValue($obj, 'uploadable_files')) . '; var customizationTextFieldNumber = ' . intval($this->getFieldValue($obj, 'text_fields')) . '; var uploadableFileLabel = 0; var textFieldLabel = 0; var defaultLanguage = ' . intval($defaultLanguage) . '; var languages = new Array();'; $i = 0; foreach ($languages as $language) { echo 'languages[' . $i++ . '] = new Array(' . intval($language['id_lang']) . ', \'' . $language['iso_code'] . '\', \'' . htmlentities($language['name'], ENT_COMPAT, 'UTF-8') . '\');' . "\n"; } echo ' </script>'; ?> <tr> <td colspan="2"> <input type="checkbox" id="is_virtual_good" name="is_virtual_good" value="true" onchange="toggleVirtualProduct(this)" onclick="toggleVirtualProduct(this);" <?php if (($productDownload->id or Tools::getValue('is_virtual_good') == 'true') and $productDownload->active) { echo 'checked="checked"'; } ?> /> <label for="is_virtual_good" class="t bold"><?php echo $this->l('Is this a downloadable product?'); ?> </label> <div id="virtual_good" <?php if (!$productDownload->id or !$productDownload->active) { echo 'style="display:none;"'; } ?> > <?php if (!ProductDownload::checkWritableDir()) { ?> <p class="alert"> <?php echo $this->l('Your download repository is not writable.'); ?> <br/> <?php echo realpath(_PS_DOWNLOAD_DIR_); ?> </p> <?php } else { ?> <?php if ($productDownload->id) { echo '<input type="hidden" id="virtual_product_id" name="virtual_product_id" value="' . $productDownload->id . '" />'; } ?> <p class="block"> <?php if (!$productDownload->checkFile()) { ?> <?php if ($productDownload->id) { ?> <p class="alert"> <?php echo $this->l('This product is missing'); ?> :<br/> <?php echo realpath(_PS_DOWNLOAD_DIR_) . '/' . $productDownload->physically_filename; ?> </p> <?php } ?> <p><?php echo $this->l('Your server\'s maximum upload file size is') . ': ' . ini_get('upload_max_filesize'); ?> </p> <?php if (!strval(Tools::getValue('virtual_product_filename'))) { ?> <label id="virtual_product_file_label" for="virtual_product_file" class="t"><?php echo $this->l('Upload a file'); ?> </label> <input type="file" id="virtual_product_file" name="virtual_product_file" value="" class="" onchange="uploadFile()" maxlength="<?php echo $this->maxFileSize; ?> " /> <?php } ?> <div id="upload-confirmation"> <?php if ($up_filename = strval(Tools::getValue('virtual_product_filename'))) { ?> <input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="<?php echo $up_filename; ?> " /> <?php } ?> </div> <?php } else { ?> <input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="<?php echo $productDownload->physically_filename; ?> " /> <?php echo $this->l('This is the link') . ': ' . $productDownload->getHtmlLink(false, true); ?> <a href="confirm.php?height=200&width=300&modal=true&referer=<?php echo rawurlencode($_SERVER['REQUEST_URI'] . '&deleteVirtualProduct=true'); ?> " class="thickbox red" title="<?php echo $this->l('Delete this file'); ?> "><?php echo $this->l('Delete this file'); ?> </a> <?php } // check if file exists ?> </p> <p class="block"> <label for="virtual_product_name" class="t"><?php echo $this->l('Filename'); ?> </label> <input type="text" id="virtual_product_name" name="virtual_product_name" class="" value="<?php echo $productDownload->id > 0 ? $productDownload->display_filename : htmlentities(Tools::getValue('virtual_product_name'), ENT_COMPAT, 'UTF-8'); ?> " /> <span class="hint" name="help_box" style="display:none;"><?php echo $this->l('The complete filename with its extension (e.g., Our best song.mp3)'); ?> </span> </p> <p class="block"> <label for="virtual_product_nb_downloable" class="t"><?php echo $this->l('Number of downloads'); ?> </label> <input type="text" id="virtual_product_nb_downloable" name="virtual_product_nb_downloable" value="<?php echo $productDownload->id > 0 ? $productDownload->nb_downloadable : htmlentities(Tools::getValue('virtual_product_nb_downloable'), ENT_COMPAT, 'UTF-8'); ?> " class="" size="6" /> <span class="hint" name="help_box" style="display:none"><?php echo $this->l('Number of authorized downloads per customer'); ?> </span> </p> <p class="block"> <label for="virtual_product_expiration_date" class="t"><?php echo $this->l('Expiration date'); ?> </label> <input type="text" id="virtual_product_expiration_date" name="virtual_product_expiration_date" value="<?php echo $productDownload->id > 0 ? (!empty($productDownload->date_expiration) and $productDownload->date_expiration != '0000-00-00 00:00:00') ? date('Y-m-d', strtotime($productDownload->date_expiration)) : '' : htmlentities(Tools::getValue('virtual_product_expiration_date'), ENT_COMPAT, 'UTF-8'); ?> " size="11" maxlength="10" autocomplete="off" /> <?php echo $this->l('Format: YYYY-MM-DD'); ?> <span class="hint" name="help_box" style="display:none"><?php echo $this->l('No expiration date if you leave this blank'); ?> </span> </p> <p class="block"> <label for="virtual_product_nb_days" class="t"><?php echo $this->l('Number of days'); ?> </label> <input type="text" id="virtual_product_nb_days" name="virtual_product_nb_days" value="<?php echo $productDownload->id > 0 ? $productDownload->nb_days_accessible : htmlentities(Tools::getValue('virtual_product_nb_days'), ENT_COMPAT, 'UTF-8'); ?> " class="" size="4" /><sup> *</sup> <span class="hint" name="help_box" style="display:none"><?php echo $this->l('How many days this file can be accessed by customers'); ?> </span> </p> <?php } // check if download directory is writable ?> </div> </td> </tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr> <script type="text/javascript"> if ($('#is_virtual_good').attr('checked')) $('#virtual_good').show('slow'); </script> <?php echo ' <tr> <td class="col-left">' . $this->l('Pre-tax wholesale price:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" name="wholesale_price" type="text" value="' . htmlentities($this->getFieldValue($obj, 'wholesale_price'), ENT_COMPAT, 'UTF-8') . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . ' <span style="margin-left:10px">' . $this->l('The wholesale price at which you bought this product') . '</span> </td> </tr>'; echo ' <tr> <td class="col-left">' . $this->l('Pre-tax retail price:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" id="priceTE" name="price" type="text" value="' . $this->getFieldValue($obj, 'price') . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\'); calcPriceTI();" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '<sup> *</sup> <span style="margin-left:2px">' . $this->l('The pre-tax retail price to sell this product') . '</span> </td> </tr>'; $taxes = Tax::getTaxes(intval($cookie->id_lang)); echo '<script type="text/javascript">'; echo 'noTax = ' . (Tax::excludeTaxeOption() ? 'true' : 'false'), ";\n"; echo 'taxesArray = new Array ();' . "\n"; echo 'taxesArray[0] = 0', ";\n"; foreach ($taxes as $k => $tax) { echo 'taxesArray[' . $tax['id_tax'] . ']=' . $tax['rate'] . "\n"; } echo ' </script>'; echo ' <tr> <td class="col-left">' . $this->l('Tax:') . '</td> <td style="padding-bottom:5px;"> <select onChange="javascript:calcPriceTI();" name="id_tax" id="id_tax" ' . (Tax::excludeTaxeOption() ? 'disabled="disabled"' : '') . '> <option value="0"' . ($this->getFieldValue($obj, 'id_tax') == 0 ? ' selected="selected"' : '') . '>' . $this->l('No tax') . '</option>'; foreach ($taxes as $k => $tax) { echo ' <option value="' . $tax['id_tax'] . '"' . ($this->getFieldValue($obj, 'id_tax') == $tax['id_tax'] ? ' selected="selected"' : '') . '>' . stripslashes($tax['name']) . ' (' . $tax['rate'] . '%)</option>'; } echo ' </select>'; if (Tax::excludeTaxeOption()) { echo '<span style="margin-left:10px; color:red;">' . $this->l('Taxes are currently disabled') . '</span> (<b><a href="index.php?tab=AdminTaxes&token=' . Tools::getAdminToken('AdminTaxes' . intval(Tab::getIdFromClassName('AdminTaxes')) . intval($cookie->id_employee)) . '">' . $this->l('Tax options') . '</a></b>)'; echo '<input type="hidden" value="' . intval($this->getFieldValue($obj, 'id_tax')) . '" name="id_tax" />'; } echo '</td> </tr> <tr> <td class="col-left">' . $this->l('Retail price with tax:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format == 1 ? ' ' . $currency->sign : '') . ' <input size="11" maxlength="14" id="priceTI" type="text" value="" onKeyUp="noComma(\'priceTI\'); calcPriceTE();" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . ' <span style="margin-left:10px"> </td> </tr> <tr> <td class="col-left">' . $this->l('Eco-tax:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" id="ecotax" name="ecotax" type="text" value="' . $this->getFieldValue($obj, 'ecotax') . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\'); if (parseInt(this.value) > getE(\'priceTE\').value) this.value = getE(\'priceTE\').value; if (isNaN(this.value)) this.value = 0;" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . ' <span style="margin-left:10px">(' . $this->l('already included in price') . ')</span> </td> </tr> <tr> <td class="col-left">' . $this->l('Reduction amount:') . '</td> <td style="padding-bottom:5px;"> ' . ($currency->format == 1 ? ' ' . $currency->sign . ' ' : '') . '<input size="11" maxlength="14" type="text" name="reduction_price" id="reduction_price" value="' . $this->getFieldValue($obj, 'reduction_price') . '" onkeyup="javascript:this.value = this.value.replace(/,/g, \'.\'); var key = window.event ? window.event.keyCode : event.which; if (key != 9) reductionPrice();" /> ' . ($currency->format == 2 ? ' ' . $currency->sign : '') . ' <span style="padding-right: 15px; padding-left: 15px; font-weight: bold">' . $this->l('OR') . '</span> <input size="10" maxlength="14" type="text" name="reduction_percent" id="reduction_percent" value="' . $this->getFieldValue($obj, 'reduction_percent') . '" onkeyup="javascript:this.value = this.value.replace(/,/g, \'.\'); var key = window.event ? window.event.keyCode : event.which; if (key != 9) reductionPercent();" /> % </td> </tr> <tr> <td class="col-left"> </td> <td>' . $this->l('available from') . ' <input type="text" id="reduction_from" name="reduction_from" value="' . (($from = $this->getFieldValue($obj, 'reduction_from') and $from != '0000-00-00' and $from != '1942-01-01') ? $from : date('Y-m-d')) . '" /> ' . $this->l('to') . ' <input type="text" id="reduction_to" name="reduction_to" value="' . (($to = $this->getFieldValue($obj, 'reduction_to') and $to != '0000-00-00' and $to != '1942-01-01') ? $to : date('Y-m-d')) . '" /> <p>' . $this->l('Leave same dates for undefined duration') . '</p> </td> </tr> <tr> <td class="col-left"> </td> <td style="padding-bottom:5px;"> <input type="checkbox" name="on_sale" id="on_sale" style="padding-top: 5px;" ' . ($this->getFieldValue($obj, 'on_sale') ? 'checked="checked"' : '') . 'value="1" /> <label for="on_sale" class="t">' . $this->l('Display "on sale" icon on product page and text on product listing') . '</label> </td> </tr> <tr> <td class="col-left"><b>' . $this->l('Final retail price:') . '</b></td> <td style="padding-bottom:5px;"> ' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<span id="finalPrice" style="font-weight: bold;"></span>' . ($currency->format == 2 ? ' ' . $currency->sign : '') . ' </td> </tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr> <tr> <td class="col-left">' . $this->l('Quantity:') . '</td> <td style="padding-bottom:5px;"><input size="3" maxlength="6" ' . $qty_state . ' name="quantity" type="text" value="' . $qty . '" ' . ((isset($_POST['attQty']) and $_POST['attQty']) ? 'onclick="alert(\'' . $this->l('Quantity is already defined by Attributes') . '.<br />' . $this->l('Delete attributes first') . '.\');" readonly="readonly" ' : '') . '/><sup> *</sup> </tr> <tr> <td class="col-left">' . $this->l('Displayed text when in-stock:') . '</td> <td style="padding-bottom:5px;">'; foreach ($languages as $language) { echo ' <div id="cavailable_now_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="30" type="text" id="available_now_' . $language['id_lang'] . '" name="available_now_' . $language['id_lang'] . '" value="' . stripslashes(htmlentities($this->getFieldValue($obj, 'available_now', $language['id_lang']), ENT_COMPAT, 'UTF-8')) . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cavailable_now'); echo ' </td> </tr> <tr> <td class="col-left">' . $this->l('Displayed text when allowed to be back-ordered:') . '</td> <td style="padding-bottom:5px;">'; foreach ($languages as $language) { echo ' <div id="cavailable_later_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="30" type="text" id="available_later_' . $language['id_lang'] . '" name="available_later_' . $language['id_lang'] . '" value="' . stripslashes(htmlentities($this->getFieldValue($obj, 'available_later', $language['id_lang']), ENT_COMPAT, 'UTF-8')) . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cavailable_later'); echo ' </td> </tr> <script type="text/javascript" src="../js/price.js"></script> <script type="text/javascript"> calcPriceTI(); </script> <tr> <td class="col-left">' . $this->l('When out of stock:') . '</td> <td style="padding-bottom:5px;"> <input type="radio" name="out_of_stock" id="out_of_stock_1" value="0" ' . (intval($this->getFieldValue($obj, 'out_of_stock')) == 0 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_1" class="t" id="label_out_of_stock_1">' . $this->l('Deny orders') . '</label> <br /><input type="radio" name="out_of_stock" id="out_of_stock_2" value="1" ' . ($this->getFieldValue($obj, 'out_of_stock') == 1 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_2" class="t" id="label_out_of_stock_2">' . $this->l('Allow orders') . '</label> <br /><input type="radio" name="out_of_stock" id="out_of_stock_3" value="2" ' . ($this->getFieldValue($obj, 'out_of_stock') == 2 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_3" class="t" id="label_out_of_stock_3">' . $this->l('Default:') . ' <i>' . $this->l(intval(Configuration::get('PS_ORDER_OUT_OF_STOCK')) ? 'Allow orders' : 'Deny orders') . '</i> (' . $this->l('as set in') . ' <a href="index.php?tab=AdminPPreferences&token=' . Tools::getAdminToken('AdminPPreferences' . intval(Tab::getIdFromClassName('AdminPPreferences')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');">' . $this->l('Preferences') . '</a>)</label> </td> </tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr> <tr> <td class="col-left"><label for="id_category_default" class="t">' . $this->l('Default category:') . '</label></td> <td> <select id="id_category_default" name="id_category_default" onchange="checkDefaultCategory(this.value);">'; $categories = Category::getCategories(intval($cookie->id_lang), false); Category::recurseCategory($categories, $categories[0][1], 1, $this->getFieldValue($obj, 'id_category_default') ? $this->getFieldValue($obj, 'id_category_default') : Tools::getValue('id_category', 1)); echo ' </select> </td> </tr> <tr> <td class="col-left">' . $this->l('Catalog:') . '</td> <td> <div style="overflow: auto; min-height: 300px; padding-top: 0.6em;" id="categoryList"> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'categoryBox[]\', this.checked)" /></th> <th>' . $this->l('ID') . '</th> <th style="width: 400px">' . $this->l('Name') . '</th> </tr>'; $done = array(); $index = array(); $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : ($obj->id ? Product::getIndexedCategories($obj->id) : array()); foreach ($indexedCategories as $k => $row) { $index[] = $row['id_category']; } $this->recurseCategoryForInclude($index, $categories, $categories[0][1], 1, $obj->id_category_default); echo ' </table> <p style="padding:0px; margin:0px 0px 10px 0px;">' . $this->l('Mark all checkbox(es) of categories in which product is to appear') . '<sup> *</sup></p> </div> </td> </tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr> <tr><td colspan="2"> <span onclick="javascript:openCloseLayer(\'seo\');" style="cursor: pointer"><img src="../img/admin/arrow.gif" alt="' . $this->l('SEO') . '" title="' . $this->l('SEO') . '" style="float:left; margin-right:5px;"/>' . $this->l('Click here to improve product\'s rank in search engines (SEO)') . '</span><br /> <div id="seo" style="display: none; padding-top: 15px;"> <table> <tr> <td class="col-left">' . $this->l('Meta title:') . '</td> <td>'; foreach ($languages as $language) { echo ' <div id="cmeta_title_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="meta_title_' . $language['id_lang'] . '" name="meta_title_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_title', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cmeta_title'); echo ' <p style="clear: both">' . $this->l('Product page title; leave blank to use product name') . '</p> </td> </tr> <tr> <td class="col-left">' . $this->l('Meta description:') . '</td> <td>'; foreach ($languages as $language) { echo ' <div id="cmeta_description_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="meta_description_' . $language['id_lang'] . '" name="meta_description_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_description', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cmeta_description'); echo ' <p style="clear: both">' . $this->l('A single sentence for HTML header') . '</p> </td> </tr> <tr> <td class="col-left">' . $this->l('Meta keywords:') . '</td> <td>'; foreach ($languages as $language) { echo ' <div id="cmeta_keywords_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="meta_keywords_' . $language['id_lang'] . '" name="meta_keywords_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_keywords', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cmeta_keywords'); echo ' <p style="clear: both">' . $this->l('Keywords for HTML header, separated by a comma') . '</p> </td> </tr> <tr> <td class="col-left">' . $this->l('Friendly URL:') . '</td> <td>'; foreach ($languages as $language) { echo ' <div id="clink_rewrite_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="link_rewrite_' . $language['id_lang'] . '" name="link_rewrite_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'link_rewrite', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" onkeyup="this.value = str2url(this.value); updateFriendlyURL();" /><sup> *</sup> <span class="hint" name="help_box">' . $this->l('Only letters and the "less" character are allowed') . '<span class="hint-pointer"> </span></span> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'clink_rewrite'); global $cookie; $iso = Language::getIsoById(intval($cookie->id_lang)); echo ' <p style="clear: both; width: 360px; word-wrap: break-word; overflow: auto;">' . $this->l('Product link will look like this:') . ' ' . (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . '/id_product-<span id="friendly-url"></span>.html</p> </td> </tr> <script type="text/javascript">updateFriendlyURL();</script>'; echo '</td></tr></table> </div> </td></tr> <tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr> <tr> <td class="col-left">' . $this->l('Short description:') . '<br /><br /><i>(' . $this->l('appears in search results') . ')</i></td> <td style="padding-bottom:5px;">'; foreach ($languages as $language) { echo ' <div id="cdesc_short_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . ';float: left;"> <textarea class="rte" cols="100" rows="10" id="description_short_' . $language['id_lang'] . '" name="description_short_' . $language['id_lang'] . '">' . htmlentities(stripslashes($this->getFieldValue($obj, 'description_short', $language['id_lang'])), ENT_COMPAT, 'UTF-8') . '</textarea> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cdesc_short'); echo ' </td> </tr> <tr> <td class="col-left">' . $this->l('Description:') . '</td> <td style="padding-bottom:5px;">'; foreach ($languages as $language) { echo ' <div id="cdesc_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . ';float: left;"> <textarea class="rte" cols="100" rows="20" id="description_' . $language['id_lang'] . '" name="description_' . $language['id_lang'] . '">' . htmlentities(stripslashes($this->getFieldValue($obj, 'description', $language['id_lang'])), ENT_COMPAT, 'UTF-8') . '</textarea> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cdesc'); echo ' </td> </tr>'; echo '<tr><td class="col-left">' . $this->l('Tags:') . '</td><td style="padding-bottom:5px;">'; foreach ($languages as $language) { echo '<div id="ctags_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="55" type="text" id="tags_' . $language['id_lang'] . '" name="tags_' . $language['id_lang'] . '" value="' . htmlentities(Tools::getValue('tags_' . $language['id_lang'], $obj->getTags($language['id_lang'], true)), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' !<>;?=+#"°{}_$%<span class="hint-pointer"> </span></span> </div>'; } $this->displayFlags($languages, $defaultLanguage, $divLangName, 'ctags'); echo '<p style="clear: both">' . $this->l('Tags separated by commas (e.g., dvd, dvd player, hifi)') . '</p>'; echo '</td> </tr>'; $accessories = Product::getAccessoriesLight(intval($cookie->id_lang), $obj->id); if ($postAccessories = Tools::getValue('inputAccessories')) { $postAccessoriesTab = explode('-', Tools::getValue('inputAccessories')); foreach ($postAccessoriesTab as $accessoryId) { if (!$this->haveThisAccessory($accessoryId, $accessories) and $accessory = Product::getAccessoryById($accessoryId)) { $accessories[] = $accessory; } } } echo ' <tr> <td class="col-left">' . $this->l('Accessories:') . '<br /><br /><i>' . $this->l('(Do not forget to Save the product afterward)') . '</i></td> <td style="padding-bottom:5px;"> <div id="divAccessories">'; foreach ($accessories as $accessory) { echo $accessory['name'] . '<span onclick="delAccessory(' . $accessory['id_product'] . ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />'; } echo '</div> <input type="hidden" name="inputAccessories" id="inputAccessories" value="'; foreach ($accessories as $accessory) { echo $accessory['id_product'] . '-'; } echo '" /> <input type="hidden" name="nameAccessories" id="nameAccessories" value="'; foreach ($accessories as $accessory) { echo $accessory['name'] . '¤'; } echo '" /> <script type="text/javascript"> var formProduct; var accessories = new Array(); function fillAccessories() { $.getJSON("' . dirname($currentIndex) . '/ajax.php",{ajaxProductAccessories:1,id_lang:' . intval($cookie->id_lang) . ',id_product:' . ($obj->id ? intval($obj->id) : 0) . '}, function(j) { for (var i = 0; i < j.length; i++) accessories[i] = new Array(j[i].value, j[i].text); formProduct = document.layers ? document.forms.product : document.product; formProduct.selectAccessories.length = accessories.length + 1; for (i = 0, j = 1; i < accessories.length; i++) { if (formProduct.filter.value) if (accessories[i][1].toLowerCase().indexOf(formProduct.filter.value.toLowerCase()) == -1) continue; formProduct.selectAccessories.options[j].value = accessories[i][0]; formProduct.selectAccessories.options[j].text = accessories[i][1]; j++; } if (j == 1) { formProduct.selectAccessories.length = 2; formProduct.selectAccessories.options[1].value = -1; formProduct.selectAccessories.options[1].text = \'' . $this->l('No match found') . '\'; formProduct.selectAccessories.options.selectedIndex = 1; } else { formProduct.selectAccessories.length = j; formProduct.selectAccessories.options.selectedIndex = (formProduct.filter.value == \'\' ? 0 : 1); } } ); } </script> <select id="selectAccessories" name="selectAccessories" style="width: 380px;"> <option value="0" selected="selected">-- ' . $this->l('Choose') . ' --</option> </select> <script type="text/javascript"> fillAccessories(); </script> <span onclick="addAccessory();" style="cursor: pointer;"><img src="../img/admin/add.gif" alt="' . $this->l('Add an accessory') . '" title="' . $this->l('Add an accessory') . '" /></span> <br />' . $this->l('Filter:') . ' <input type="text" size="25" name="filter" onkeyup="fillAccessories();" class="space" /> </td> </tr> <tr><td colspan="2" style="padding-bottom:10px;"><hr style="width:730px;"></td></tr> <tr> <td colspan="2" style="text-align:center;"> <input type="submit" value="' . $this->l('Save') . '" name="submitAdd' . $this->table . '" class="button" /> <input type="submit" value="' . $this->l('Save and stay') . '" name="submitAdd' . $this->table . 'AndStay" class="button" /></td> </tr> </table> </div> <script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script> <script type="text/javascript"> function tinyMCEInit(element) { $().ready(function() { $(element).tinymce({ // Location of TinyMCE script script_url : \'' . __PS_BASE_URI__ . 'js/tinymce/jscripts/tiny_mce/tiny_mce.js\', // General options theme : "advanced", plugins : "safari,pagebreak,style,layer,table,advimage,advlink,inlinepopups,media,searchreplace,contextmenu,paste,directionality,fullscreen", // Theme options theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,,|,forecolor,backcolor", theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,media,|,ltr,rtl,|,fullscreen", theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,pagebreak", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", width : "100", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, content_css : "' . __PS_BASE_URI__ . 'themes/' . _THEME_NAME_ . '/css/global.css", // Drop lists for link/image/media/template dialogs template_external_list_url : "lists/template_list.js", external_link_list_url : "lists/link_list.js", external_image_list_url : "lists/image_list.js", media_external_list_url : "lists/media_list.js", elements : "nourlconvert", convert_urls : false, language : "' . (file_exists(_PS_ROOT_DIR_ . '/js/tinymce/jscripts/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en') . '" }); }); } tinyMCEInit(\'textarea.rte\'); toggleVirtualProduct(getE(\'is_virtual_good\')); </script> '; }
public function initFormAssociations($obj) { $product = $obj; $data = $this->createTemplate($this->tpl_form); // Prepare Categories tree for display in Associations tab $root = Category::getRootCategory(); $default_category = $this->context->cookie->id_category_products_filter ? $this->context->cookie->id_category_products_filter : Context::getContext()->shop->id_category; if (!$product->id || !$product->isAssociatedToShop()) { $selected_cat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); } else { if (Tools::isSubmit('categoryBox')) { $selected_cat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); } else { $selected_cat = Product::getProductCategoriesFull($product->id, $this->default_form_language); } } // Multishop block $data->assign('feature_shop_active', Shop::isFeatureActive()); $helper = new HelperForm(); if ($this->object && $this->object->id) { $helper->id = $this->object->id; } else { $helper->id = null; } $helper->table = $this->table; $helper->identifier = $this->identifier; // Accessories block $accessories = Product::getAccessoriesLight($this->context->language->id, $product->id); if ($post_accessories = Tools::getValue('inputAccessories')) { $post_accessories_tab = explode('-', Tools::getValue('inputAccessories')); foreach ($post_accessories_tab as $accessory_id) { if (!$this->haveThisAccessory($accessory_id, $accessories) && ($accessory = Product::getAccessoryById($accessory_id))) { $accessories[] = $accessory; } } } $data->assign('accessories', $accessories); $product->manufacturer_name = Manufacturer::getNameById($product->id_manufacturer); $categories = array(); foreach ($selected_cat as $key => $category) { $categories[] = $key; } $tree = new HelperTreeCategories('associated-categories-tree', 'Associated categories'); $tree->setTemplate('tree_associated_categories.tpl')->setHeaderTemplate('tree_associated_header.tpl')->setRootCategory($root->id)->setUseCheckBox(true)->setUseSearch(true)->setSelectedCategories($categories); $data->assign(array('default_category' => $default_category, 'selected_cat_ids' => implode(',', array_keys($selected_cat)), 'selected_cat' => $selected_cat, 'id_category_default' => $product->getDefaultCategory(), 'category_tree' => $tree->render(), 'product' => $product, 'link' => $this->context->link, 'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP)); $this->tpl_form_vars['custom_form'] = $data->fetch(); }
/** * Create a link to a product * * @param mixed $product Product object (can be an ID product, but deprecated) * @param string $alias * @param string $category * @param string $ean13 * @param int $id_lang * @param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart * @param int $ipa ID product attribute * @return string */ public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null, $ipa = 0, $force_routes = false) { $dispatcher = Dispatcher::getInstance(); if (!$id_lang) { $id_lang = Context::getContext()->language->id; } if (!$id_shop) { $shop = Context::getContext()->shop; } else { $shop = new Shop($id_shop); } $url = 'http://' . $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang); if (!is_object($product)) { if (is_array($product) && isset($product['id_product'])) { $product = new Product($product['id_product'], false, $id_lang); } else { if (is_numeric($product) || !$product) { $product = new Product($product, false, $id_lang); } else { throw new PrestaShopException('Invalid product vars'); } } } // Set available keywords $params = array(); $params['id'] = $product->id; $params['rewrite'] = !$alias ? $product->getFieldByLang('link_rewrite') : $alias; $params['ean13'] = !$ean13 ? $product->ean13 : $ean13; $params['category'] = !$category ? $product->category : $category; $params['meta_keywords'] = Tools::str2url($product->getFieldByLang('meta_keywords')); $params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title')); if ($dispatcher->hasKeyword('product_rule', $id_lang, 'manufacturer')) { $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer)); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'supplier')) { $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier)); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'price')) { $params['price'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specificPrice); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'tags')) { $params['tags'] = Tools::str2url($product->getTags($id_lang)); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'reference')) { $params['reference'] = Tools::str2url($product->reference); } if ($dispatcher->hasKeyword('product_rule', $id_lang, 'categories')) { $cats = array(); foreach ($product->getParentCategories() as $cat) { $cats[] = $cat['link_rewrite']; } $params['categories'] = implode('/', $cats); } $anchor = $ipa ? $product->getAnchor($ipa) : ''; return $url . $dispatcher->createUrl('product_rule', $id_lang, $params, $force_routes, $anchor); }
public function renderFormAddress() { // Change table and className for addresses $this->table = 'address'; $this->className = 'Address'; $id_address = Tools::getValue('id_address'); // Create Object Address $address = new Address($id_address); $form = array('legend' => array('title' => $this->l('Addresses'), 'image' => '../img/admin/contact.gif')); if (!$address->id_manufacturer || !Manufacturer::manufacturerExists($address->id_manufacturer)) { $form['input'][] = array('type' => 'select', 'label' => $this->l('Choose the manufacturer:'), 'name' => 'id_manufacturer', 'options' => array('query' => Manufacturer::getManufacturers(), 'id' => 'id_manufacturer', 'name' => 'name')); } else { $form['input'][] = array('type' => 'text', 'label' => $this->l('Manufacturer:'), 'name' => 'name', 'disabled' => true); $form['input'][] = array('type' => 'hidden', 'name' => 'id_manufacturer'); } $form['input'][] = array('type' => 'hidden', 'name' => 'alias'); $form['input'][] = array('type' => 'text', 'label' => $this->l('Last name:'), 'name' => 'lastname', 'size' => 33, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' 0-9!<>,;?=+()@#"�{}_$%:'); $form['input'][] = array('type' => 'text', 'label' => $this->l('First name:'), 'name' => 'firstname', 'size' => 33, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' 0-9!<>,;?=+()@#"�{}_$%:'); $form['input'][] = array('type' => 'text', 'label' => $this->l('Address:'), 'name' => 'address1', 'size' => 33, 'required' => true); $form['input'][] = array('type' => 'text', 'label' => $this->l('Address (2):'), 'name' => 'address2', 'size' => 33, 'required' => false); $form['input'][] = array('type' => 'text', 'label' => $this->l('Postcode / Zip Code:'), 'name' => 'postcode', 'size' => 33, 'required' => false); $form['input'][] = array('type' => 'text', 'label' => $this->l('City:'), 'name' => 'city', 'size' => 33, 'required' => true); $form['input'][] = array('type' => 'select', 'label' => $this->l('Country:'), 'name' => 'id_country', 'required' => false, 'default_value' => (int) $this->context->country->id, 'options' => array('query' => Country::getCountries($this->context->language->id), 'id' => 'id_country', 'name' => 'name')); $form['input'][] = array('type' => 'select', 'label' => $this->l('State:'), 'name' => 'id_state', 'required' => false, 'options' => array('query' => array(), 'id' => 'id_state', 'name' => 'name')); $form['input'][] = array('type' => 'text', 'label' => $this->l('Home phone:'), 'name' => 'phone', 'size' => 33, 'required' => false); $form['input'][] = array('type' => 'text', 'label' => $this->l('Mobile phone:'), 'name' => 'phone_mobile', 'size' => 33, 'required' => false); $form['input'][] = array('type' => 'textarea', 'label' => $this->l('Other:'), 'name' => 'other', 'cols' => 36, 'rows' => 4, 'required' => false, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'); $form['submit'] = array('title' => $this->l(' Save '), 'class' => 'button'); $this->fields_value = array('name' => Manufacturer::getNameById($address->id_manufacturer), 'alias' => 'manufacturer', 'id_country' => Configuration::get('PS_COUNTRY_DEFAULT')); $this->initToolbar(); $this->fields_form[0]['form'] = $form; $this->getlanguages(); $helper = new HelperForm(); $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = $this->table; $helper->identifier = $this->identifier; $helper->title = $this->l('Edit Addresses'); $helper->id = $address->id; $helper->toolbar_scroll = true; $helper->languages = $this->_languages; $helper->default_form_language = $this->default_form_language; $helper->allow_employee_form_lang = $this->allow_employee_form_lang; $helper->fields_value = $this->getFieldsValue($address); $helper->toolbar_btn = $this->toolbar_btn; $this->content .= $helper->generateForm($this->fields_form); }
public function postProcess() { // If id_order is sent, we instanciate a new Order object if (Tools::isSubmit('id_order') && Tools::getValue('id_order') > 0) { $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { throw new PrestaShopException('Can\'t load Order object'); } ShopUrl::cacheMainDomainForShop((int) $order->id_shop); } /* Update shipping number */ if (Tools::isSubmit('submitShippingNumber') && isset($order)) { if ($this->tabAccess['edit'] === '1') { $order_carrier = new OrderCarrier(Tools::getValue('id_order_carrier')); if (!Validate::isLoadedObject($order_carrier)) { $this->errors[] = Tools::displayError('The order carrier ID is invalid.'); } elseif (!Validate::isTrackingNumber(Tools::getValue('tracking_number'))) { $this->errors[] = Tools::displayError('The tracking number is incorrect.'); } else { // update shipping number // Keep these two following lines for backward compatibility, remove on 1.6 version $order->shipping_number = Tools::getValue('tracking_number'); $order->update(); //NOX uprav na status SHIPPED (4) $stav_objednavky = $order->getCurrentState(); if ($stav_objednavky != 4) { $order->setCurrentState(4); } // Update order_carrier $order_carrier->tracking_number = pSQL(Tools::getValue('tracking_number')); if ($order_carrier->update()) { // Send mail to customer $customer = new Customer((int) $order->id_customer); $carrier = new Carrier((int) $order->id_carrier, $order->id_lang); if (!Validate::isLoadedObject($customer)) { throw new PrestaShopException('Can\'t load Customer object'); } if (!Validate::isLoadedObject($carrier)) { throw new PrestaShopException('Can\'t load Carrier object'); } //NOX dodatecne udaje do emailu $produkty = $order->getCartProducts(); foreach ($produkty as $key => $value) { $nazev .= $value['product_name'] . ", "; $znacka .= Manufacturer::getNameById($value['id_manufacturer']) . " "; } $nazev = substr($nazev, 0, -2); $test = 123; $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{id_order}' => $order->id, '{shipping_number}' => $order->shipping_number, '{order_name}' => $order->getUniqReference(), '{nazev_hodinek}' => $nazev, '{znacka}' => $znacka); if (@Mail::Send((int) $order->id_lang, 'in_transit', Mail::l('Package in transit', (int) $order->id_lang), $templateVars, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop)) { Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order, 'customer' => $customer, 'carrier' => $carrier)); Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token); } else { $this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.'); } } else { $this->errors[] = Tools::displayError('The order carrier cannot be updated.'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitState') && isset($order)) { if ($this->tabAccess['edit'] === '1') { $order_state = new OrderState(Tools::getValue('id_order_state')); if (!Validate::isLoadedObject($order_state)) { $this->errors[] = Tools::displayError('The new order status is invalid.'); } else { $current_order_state = $order->getCurrentOrderState(); if ($current_order_state->id != $order_state->id) { // Create new OrderHistory $history = new OrderHistory(); $history->id_order = $order->id; $history->id_employee = (int) $this->context->employee->id; $use_existings_payment = false; if (!$order->hasInvoice()) { $use_existings_payment = true; } $history->changeIdOrderState((int) $order_state->id, $order, $use_existings_payment); $carrier = new Carrier($order->id_carrier, $order->id_lang); $templateVars = array(); if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) { $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url)); } // Save all changes if ($history->addWithemail(true, $templateVars)) { // synchronizes quantities if needed.. if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { foreach ($order->getProducts() as $product) { if (StockAvailable::dependsOnStock($product['product_id'])) { StockAvailable::synchronize($product['product_id'], (int) $product['id_shop']); } } } Tools::redirectAdmin(self::$currentIndex . '&id_order=' . (int) $order->id . '&vieworder&token=' . $this->token); } $this->errors[] = Tools::displayError('An error occurred while changing order status, or we were unable to send an email to the customer.'); } else { $this->errors[] = Tools::displayError('The order has already been assigned this status.'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitMessage') && isset($order)) { if ($this->tabAccess['edit'] === '1') { $customer = new Customer(Tools::getValue('id_customer')); if (!Validate::isLoadedObject($customer)) { $this->errors[] = Tools::displayError('The customer is invalid.'); } elseif (!Tools::getValue('message')) { $this->errors[] = Tools::displayError('The message cannot be blank.'); } else { /* Get message rules and and check fields validity */ $rules = call_user_func(array('Message', 'getValidationRules'), 'Message'); foreach ($rules['required'] as $field) { if (($value = Tools::getValue($field)) == false && (string) $value != '0') { if (!Tools::getValue('id_' . $this->table) || $field != 'passwd') { $this->errors[] = sprintf(Tools::displayError('field %s is required.'), $field); } } } foreach ($rules['size'] as $field => $maxLength) { if (Tools::getValue($field) && Tools::strlen(Tools::getValue($field)) > $maxLength) { $this->errors[] = sprintf(Tools::displayError('field %1$s is too long (%2$d chars max).'), $field, $maxLength); } } foreach ($rules['validate'] as $field => $function) { if (Tools::getValue($field)) { if (!Validate::$function(htmlentities(Tools::getValue($field), ENT_COMPAT, 'UTF-8'))) { $this->errors[] = sprintf(Tools::displayError('field %s is invalid.'), $field); } } } if (!count($this->errors)) { //check if a thread already exist $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($customer->email, $order->id); if (!$id_customer_thread) { $customer_thread = new CustomerThread(); $customer_thread->id_contact = 0; $customer_thread->id_customer = (int) $order->id_customer; $customer_thread->id_shop = (int) $this->context->shop->id; $customer_thread->id_order = (int) $order->id; $customer_thread->id_lang = (int) $this->context->language->id; $customer_thread->email = $customer->email; $customer_thread->status = 'open'; $customer_thread->token = Tools::passwdGen(12); $customer_thread->add(); } else { $customer_thread = new CustomerThread((int) $id_customer_thread); } $customer_message = new CustomerMessage(); $customer_message->id_customer_thread = $customer_thread->id; $customer_message->id_employee = (int) $this->context->employee->id; $customer_message->message = Tools::getValue('message'); $customer_message->private = Tools::getValue('visibility'); if (!$customer_message->add()) { $this->errors[] = Tools::displayError('An error occurred while saving the message.'); } elseif ($customer_message->private) { Tools::redirectAdmin(self::$currentIndex . '&id_order=' . (int) $order->id . '&vieworder&conf=11&token=' . $this->token); } else { $message = $customer_message->message; if (Configuration::get('PS_MAIL_TYPE', null, null, $order->id_shop) != Mail::TYPE_TEXT) { $message = Tools::nl2br($customer_message->message); } $varsTpl = array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => $order->id, '{order_name}' => $order->getUniqReference(), '{message}' => $message); if (@Mail::Send((int) $order->id_lang, 'order_merchant_comment', Mail::l('New message regarding your order', (int) $order->id_lang), $varsTpl, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop)) { Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=11' . '&token=' . $this->token); } } $this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } } elseif (Tools::isSubmit('partialRefund') && isset($order)) { if ($this->tabAccess['edit'] == '1') { if (is_array($_POST['partialRefundProduct'])) { $amount = 0; $order_detail_list = array(); foreach ($_POST['partialRefundProduct'] as $id_order_detail => $amount_detail) { $order_detail_list[$id_order_detail]['quantity'] = (int) $_POST['partialRefundProductQuantity'][$id_order_detail]; if (empty($amount_detail)) { $order_detail = new OrderDetail((int) $id_order_detail); $order_detail_list[$id_order_detail]['amount'] = $order_detail->unit_price_tax_incl * $order_detail_list[$id_order_detail]['quantity']; } else { $order_detail_list[$id_order_detail]['amount'] = (double) str_replace(',', '.', $amount_detail); } $amount += $order_detail_list[$id_order_detail]['amount']; $order_detail = new OrderDetail((int) $id_order_detail); if (!$order->hasBeenDelivered() || $order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities') && $order_detail_list[$id_order_detail]['quantity'] > 0) { $this->reinjectQuantity($order_detail, $order_detail_list[$id_order_detail]['quantity']); } } $shipping_cost_amount = (double) str_replace(',', '.', Tools::getValue('partialRefundShippingCost')); if ($shipping_cost_amount > 0) { $amount += $shipping_cost_amount; } $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier()); if (Validate::isLoadedObject($order_carrier)) { $order_carrier->weight = (double) $order->getTotalWeight(); if ($order_carrier->update()) { $order->weight = sprintf("%.3f " . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); } } if ($amount > 0) { if (!OrderSlip::createPartialOrderSlip($order, $amount, $shipping_cost_amount, $order_detail_list)) { $this->errors[] = Tools::displayError('You cannot generate a partial credit slip.'); } // Generate voucher if (Tools::isSubmit('generateDiscountRefund') && !count($this->errors)) { $cart_rule = new CartRule(); $cart_rule->description = sprintf($this->l('Credit slip for order #%d'), $order->id); $languages = Language::getLanguages(false); foreach ($languages as $language) { // Define a temporary name $cart_rule->name[$language['id_lang']] = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id); } // Define a temporary code $cart_rule->code = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id); $cart_rule->quantity = 1; $cart_rule->quantity_per_user = 1; // Specific to the customer $cart_rule->id_customer = $order->id_customer; $now = time(); $cart_rule->date_from = date('Y-m-d H:i:s', $now); $cart_rule->date_to = date('Y-m-d H:i:s', $now + 3600 * 24 * 365.25); /* 1 year */ $cart_rule->partial_use = 1; $cart_rule->active = 1; $cart_rule->reduction_amount = $amount; $cart_rule->reduction_tax = true; $cart_rule->minimum_amount_currency = $order->id_currency; $cart_rule->reduction_currency = $order->id_currency; if (!$cart_rule->add()) { $this->errors[] = Tools::displayError('You cannot generate a voucher.'); } else { // Update the voucher code and name foreach ($languages as $language) { $cart_rule->name[$language['id_lang']] = sprintf('V%1$dC%2$dO%3$d', $cart_rule->id, $order->id_customer, $order->id); } $cart_rule->code = sprintf('V%1$dC%2$dO%3$d', $cart_rule->id, $order->id_customer, $order->id); if (!$cart_rule->update()) { $this->errors[] = Tools::displayError('You cannot generate a voucher.'); } else { $currency = $this->context->currency; $customer = new Customer((int) $order->id_customer); $params['{lastname}'] = $customer->lastname; $params['{firstname}'] = $customer->firstname; $params['{id_order}'] = $order->id; $params['{order_name}'] = $order->getUniqReference(); $params['{voucher_amount}'] = Tools::displayPrice($cart_rule->reduction_amount, $currency, false); $params['{voucher_num}'] = $cart_rule->code; $customer = new Customer((int) $order->id_customer); @Mail::Send((int) $order->id_lang, 'voucher', sprintf(Mail::l('New voucher regarding your order %s', (int) $order->id_lang), $order->reference), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop); } } } } else { $this->errors[] = Tools::displayError('You have to enter an amount if you want to create a partial credit slip.'); } // Redirect if no errors if (!count($this->errors)) { Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=30&token=' . $this->token); } } else { $this->errors[] = Tools::displayError('The partial refund data is incorrect.'); } } else { $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } } elseif (Tools::isSubmit('cancelProduct') && isset($order)) { if ($this->tabAccess['delete'] === '1') { if (!Tools::isSubmit('id_order_detail') && !Tools::isSubmit('id_customization')) { $this->errors[] = Tools::displayError('You must select a product.'); } elseif (!Tools::isSubmit('cancelQuantity') && !Tools::isSubmit('cancelCustomizationQuantity')) { $this->errors[] = Tools::displayError('You must enter a quantity.'); } else { $productList = Tools::getValue('id_order_detail'); if ($productList) { $productList = array_map('intval', $productList); } $customizationList = Tools::getValue('id_customization'); if ($customizationList) { $customizationList = array_map('intval', $customizationList); } $qtyList = Tools::getValue('cancelQuantity'); if ($qtyList) { $qtyList = array_map('intval', $qtyList); } $customizationQtyList = Tools::getValue('cancelCustomizationQuantity'); if ($customizationQtyList) { $customizationQtyList = array_map('intval', $customizationQtyList); } $full_product_list = $productList; $full_quantity_list = $qtyList; if ($customizationList) { foreach ($customizationList as $key => $id_order_detail) { $full_product_list[(int) $id_order_detail] = $id_order_detail; if (isset($customizationQtyList[$key])) { $full_quantity_list[(int) $id_order_detail] += $customizationQtyList[$key]; } } } if ($productList || $customizationList) { if ($productList) { $id_cart = Cart::getCartIdByOrderId($order->id); $customization_quantities = Customization::countQuantityByCart($id_cart); foreach ($productList as $key => $id_order_detail) { $qtyCancelProduct = abs($qtyList[$key]); if (!$qtyCancelProduct) { $this->errors[] = Tools::displayError('No quantity has been selected for this product.'); } $order_detail = new OrderDetail($id_order_detail); $customization_quantity = 0; if (array_key_exists($order_detail->product_id, $customization_quantities) && array_key_exists($order_detail->product_attribute_id, $customization_quantities[$order_detail->product_id])) { $customization_quantity = (int) $customization_quantities[$order_detail->product_id][$order_detail->product_attribute_id]; } if ($order_detail->product_quantity - $customization_quantity - $order_detail->product_quantity_refunded - $order_detail->product_quantity_return < $qtyCancelProduct) { $this->errors[] = Tools::displayError('An invalid quantity was selected for this product.'); } } } if ($customizationList) { $customization_quantities = Customization::retrieveQuantitiesFromIds(array_keys($customizationList)); foreach ($customizationList as $id_customization => $id_order_detail) { $qtyCancelProduct = abs($customizationQtyList[$id_customization]); $customization_quantity = $customization_quantities[$id_customization]; if (!$qtyCancelProduct) { $this->errors[] = Tools::displayError('No quantity has been selected for this product.'); } if ($qtyCancelProduct > $customization_quantity['quantity'] - ($customization_quantity['quantity_refunded'] + $customization_quantity['quantity_returned'])) { $this->errors[] = Tools::displayError('An invalid quantity was selected for this product.'); } } } if (!count($this->errors) && $productList) { foreach ($productList as $key => $id_order_detail) { $qty_cancel_product = abs($qtyList[$key]); $order_detail = new OrderDetail((int) $id_order_detail); if (!$order->hasBeenDelivered() || $order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities') && $qty_cancel_product > 0) { $this->reinjectQuantity($order_detail, $qty_cancel_product); } // Delete product $order_detail = new OrderDetail((int) $id_order_detail); if (!$order->deleteProduct($order, $order_detail, $qty_cancel_product)) { $this->errors[] = Tools::displayError('An error occurred while attempting to delete the product.') . ' <span class="bold">' . $order_detail->product_name . '</span>'; } // Update weight SUM $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier()); if (Validate::isLoadedObject($order_carrier)) { $order_carrier->weight = (double) $order->getTotalWeight(); if ($order_carrier->update()) { $order->weight = sprintf("%.3f " . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); } } Hook::exec('actionProductCancel', array('order' => $order, 'id_order_detail' => (int) $id_order_detail)); } } if (!count($this->errors) && $customizationList) { foreach ($customizationList as $id_customization => $id_order_detail) { $order_detail = new OrderDetail((int) $id_order_detail); $qtyCancelProduct = abs($customizationQtyList[$id_customization]); if (!$order->deleteCustomization($id_customization, $qtyCancelProduct, $order_detail)) { $this->errors[] = Tools::displayError('An error occurred while attempting to delete product customization.') . ' ' . $id_customization; } } } // E-mail params if ((Tools::isSubmit('generateCreditSlip') || Tools::isSubmit('generateDiscount')) && !count($this->errors)) { $customer = new Customer((int) $order->id_customer); $params['{lastname}'] = $customer->lastname; $params['{firstname}'] = $customer->firstname; $params['{id_order}'] = $order->id; $params['{order_name}'] = $order->getUniqReference(); } // Generate credit slip if (Tools::isSubmit('generateCreditSlip') && !count($this->errors)) { if (!OrderSlip::createOrderSlip($order, $full_product_list, $full_quantity_list, Tools::isSubmit('shippingBack'))) { $this->errors[] = Tools::displayError('A credit slip cannot be generated. '); } else { Hook::exec('actionOrderSlipAdd', array('order' => $order, 'productList' => $full_product_list, 'qtyList' => $full_quantity_list)); @Mail::Send((int) $order->id_lang, 'credit_slip', Mail::l('New credit slip regarding your order', (int) $order->id_lang), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop); } } // Generate voucher if (Tools::isSubmit('generateDiscount') && !count($this->errors)) { $cartrule = new CartRule(); $languages = Language::getLanguages($order); $cartrule->description = sprintf($this->l('Credit card slip for order #%d'), $order->id); foreach ($languages as $language) { // Define a temporary name $cartrule->name[$language['id_lang']] = 'V0C' . (int) $order->id_customer . 'O' . (int) $order->id; } // Define a temporary code $cartrule->code = 'V0C' . (int) $order->id_customer . 'O' . (int) $order->id; $cartrule->quantity = 1; $cartrule->quantity_per_user = 1; // Specific to the customer $cartrule->id_customer = $order->id_customer; $now = time(); $cartrule->date_from = date('Y-m-d H:i:s', $now); $cartrule->date_to = date('Y-m-d H:i:s', $now + 3600 * 24 * 365.25); /* 1 year */ $cartrule->active = 1; $products = $order->getProducts(false, $full_product_list, $full_quantity_list); $total = 0; foreach ($products as $product) { $total += $product['unit_price_tax_incl'] * $product['product_quantity']; } if (Tools::isSubmit('shippingBack')) { $total += $order->total_shipping; } $cartrule->reduction_amount = $total; $cartrule->reduction_tax = true; $cartrule->minimum_amount_currency = $order->id_currency; $cartrule->reduction_currency = $order->id_currency; if (!$cartrule->add()) { $this->errors[] = Tools::displayError('You cannot generate a voucher.'); } else { // Update the voucher code and name foreach ($languages as $language) { $cartrule->name[$language['id_lang']] = 'V' . (int) $cartrule->id . 'C' . (int) $order->id_customer . 'O' . $order->id; } $cartrule->code = 'V' . (int) $cartrule->id . 'C' . (int) $order->id_customer . 'O' . $order->id; if (!$cartrule->update()) { $this->errors[] = Tools::displayError('You cannot generate a voucher.'); } else { $currency = $this->context->currency; $params['{voucher_amount}'] = Tools::displayPrice($cartrule->reduction_amount, $currency, false); $params['{voucher_num}'] = $cartrule->code; @Mail::Send((int) $order->id_lang, 'voucher', sprintf(Mail::l('New voucher regarding your order %s', (int) $order->id_lang), $order->reference), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop); } } } } else { $this->errors[] = Tools::displayError('No product or quantity has been selected.'); } // Redirect if no errors if (!count($this->errors)) { Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=31&token=' . $this->token); } } } else { $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } } elseif (Tools::isSubmit('messageReaded')) { Message::markAsReaded(Tools::getValue('messageReaded'), $this->context->employee->id); } elseif (Tools::isSubmit('submitAddPayment') && isset($order)) { if ($this->tabAccess['edit'] === '1') { $amount = str_replace(',', '.', Tools::getValue('payment_amount')); $currency = new Currency(Tools::getValue('payment_currency')); $order_has_invoice = $order->hasInvoice(); if ($order_has_invoice) { $order_invoice = new OrderInvoice(Tools::getValue('payment_invoice')); } else { $order_invoice = null; } if (!Validate::isLoadedObject($order)) { $this->errors[] = Tools::displayError('The order cannot be found'); } elseif (!Validate::isNegativePrice($amount) || !(double) $amount) { $this->errors[] = Tools::displayError('The amount is invalid.'); } elseif (!Validate::isString(Tools::getValue('payment_method'))) { $this->errors[] = Tools::displayError('The selected payment method is invalid.'); } elseif (!Validate::isString(Tools::getValue('payment_transaction_id'))) { $this->errors[] = Tools::displayError('The transaction ID is invalid.'); } elseif (!Validate::isLoadedObject($currency)) { $this->errors[] = Tools::displayError('The selected currency is invalid.'); } elseif ($order_has_invoice && !Validate::isLoadedObject($order_invoice)) { $this->errors[] = Tools::displayError('The invoice is invalid.'); } elseif (!Validate::isDate(Tools::getValue('payment_date'))) { $this->errors[] = Tools::displayError('The date is invalid'); } else { if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date'), $order_invoice)) { $this->errors[] = Tools::displayError('An error occurred during payment.'); } else { Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitEditNote')) { $note = Tools::getValue('note'); $order_invoice = new OrderInvoice((int) Tools::getValue('id_order_invoice')); if (Validate::isLoadedObject($order_invoice) && Validate::isCleanHtml($note)) { if ($this->tabAccess['edit'] === '1') { $order_invoice->note = $note; if ($order_invoice->save()) { Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order_invoice->id_order . '&vieworder&conf=4&token=' . $this->token); } else { $this->errors[] = Tools::displayError('The invoice note was not saved.'); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } else { $this->errors[] = Tools::displayError('The invoice for edit note was unable to load. '); } } elseif (Tools::isSubmit('submitAddOrder') && ($id_cart = Tools::getValue('id_cart')) && ($module_name = Tools::getValue('payment_module_name')) && ($id_order_state = Tools::getValue('id_order_state')) && Validate::isModuleName($module_name)) { if ($this->tabAccess['edit'] === '1') { $payment_module = Module::getInstanceByName($module_name); $cart = new Cart((int) $id_cart); Context::getContext()->currency = new Currency((int) $cart->id_currency); Context::getContext()->customer = new Customer((int) $cart->id_customer); $employee = new Employee((int) Context::getContext()->cookie->id_employee); $payment_module->validateOrder((int) $cart->id, (int) $id_order_state, $cart->getOrderTotal(true, Cart::BOTH), $payment_module->displayName, $this->l('Manual order -- Employee:') . substr($employee->firstname, 0, 1) . '. ' . $employee->lastname, array(), null, false, $cart->secure_key); if ($payment_module->currentOrder) { Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $payment_module->currentOrder . '&vieworder' . '&token=' . $this->token); } } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } elseif ((Tools::isSubmit('submitAddressShipping') || Tools::isSubmit('submitAddressInvoice')) && isset($order)) { if ($this->tabAccess['edit'] === '1') { $address = new Address(Tools::getValue('id_address')); if (Validate::isLoadedObject($address)) { // Update the address on order if (Tools::isSubmit('submitAddressShipping')) { $order->id_address_delivery = $address->id; } elseif (Tools::isSubmit('submitAddressInvoice')) { $order->id_address_invoice = $address->id; } $order->update(); Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token); } else { $this->errors[] = Tools::displayError('This address can\'t be loaded'); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitChangeCurrency') && isset($order)) { if ($this->tabAccess['edit'] === '1') { if (Tools::getValue('new_currency') != $order->id_currency && !$order->valid) { $old_currency = new Currency($order->id_currency); $currency = new Currency(Tools::getValue('new_currency')); if (!Validate::isLoadedObject($currency)) { throw new PrestaShopException('Can\'t load Currency object'); } // Update order detail amount foreach ($order->getOrderDetailList() as $row) { $order_detail = new OrderDetail($row['id_order_detail']); $fields = array('ecotax', 'product_price', 'reduction_amount', 'total_shipping_price_tax_excl', 'total_shipping_price_tax_incl', 'total_price_tax_incl', 'total_price_tax_excl', 'product_quantity_discount', 'purchase_supplier_price', 'reduction_amount', 'reduction_amount_tax_incl', 'reduction_amount_tax_excl', 'unit_price_tax_incl', 'unit_price_tax_excl', 'original_product_price'); foreach ($fields as $field) { $order_detail->{$field} = Tools::convertPriceFull($order_detail->{$field}, $old_currency, $currency); } $order_detail->update(); $order_detail->updateTaxAmount($order); } $id_order_carrier = (int) $order->getIdOrderCarrier(); if ($id_order_carrier) { $order_carrier = $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier()); $order_carrier->shipping_cost_tax_excl = (double) Tools::convertPriceFull($order_carrier->shipping_cost_tax_excl, $old_currency, $currency); $order_carrier->shipping_cost_tax_incl = (double) Tools::convertPriceFull($order_carrier->shipping_cost_tax_incl, $old_currency, $currency); $order_carrier->update(); } // Update order && order_invoice amount $fields = array('total_discounts', 'total_discounts_tax_incl', 'total_discounts_tax_excl', 'total_discount_tax_excl', 'total_discount_tax_incl', 'total_paid', 'total_paid_tax_incl', 'total_paid_tax_excl', 'total_paid_real', 'total_products', 'total_products_wt', 'total_shipping', 'total_shipping_tax_incl', 'total_shipping_tax_excl', 'total_wrapping', 'total_wrapping_tax_incl', 'total_wrapping_tax_excl'); $invoices = $order->getInvoicesCollection(); if ($invoices) { foreach ($invoices as $invoice) { foreach ($fields as $field) { if (isset($invoice->{$field})) { $invoice->{$field} = Tools::convertPriceFull($invoice->{$field}, $old_currency, $currency); } } $invoice->save(); } } foreach ($fields as $field) { if (isset($order->{$field})) { $order->{$field} = Tools::convertPriceFull($order->{$field}, $old_currency, $currency); } } // Update currency in order $order->id_currency = $currency->id; // Update exchange rate $order->conversion_rate = (double) $currency->conversion_rate; $order->update(); } else { $this->errors[] = Tools::displayError('You cannot change the currency.'); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitGenerateInvoice') && isset($order)) { if (!Configuration::get('PS_INVOICE', null, null, $order->id_shop)) { $this->errors[] = Tools::displayError('Invoice management has been disabled.'); } elseif ($order->hasInvoice()) { $this->errors[] = Tools::displayError('This order already has an invoice.'); } else { $order->setInvoice(true); Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token); } } elseif (Tools::isSubmit('submitDeleteVoucher') && isset($order)) { if ($this->tabAccess['edit'] === '1') { $order_cart_rule = new OrderCartRule(Tools::getValue('id_order_cart_rule')); if (Validate::isLoadedObject($order_cart_rule) && $order_cart_rule->id_order == $order->id) { if ($order_cart_rule->id_order_invoice) { $order_invoice = new OrderInvoice($order_cart_rule->id_order_invoice); if (!Validate::isLoadedObject($order_invoice)) { throw new PrestaShopException('Can\'t load Order Invoice object'); } // Update amounts of Order Invoice $order_invoice->total_discount_tax_excl -= $order_cart_rule->value_tax_excl; $order_invoice->total_discount_tax_incl -= $order_cart_rule->value; $order_invoice->total_paid_tax_excl += $order_cart_rule->value_tax_excl; $order_invoice->total_paid_tax_incl += $order_cart_rule->value; // Update Order Invoice $order_invoice->update(); } // Update amounts of order $order->total_discounts -= $order_cart_rule->value; $order->total_discounts_tax_incl -= $order_cart_rule->value; $order->total_discounts_tax_excl -= $order_cart_rule->value_tax_excl; $order->total_paid += $order_cart_rule->value; $order->total_paid_tax_incl += $order_cart_rule->value; $order->total_paid_tax_excl += $order_cart_rule->value_tax_excl; // Delete Order Cart Rule and update Order $order_cart_rule->delete(); $order->update(); Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token); } else { $this->errors[] = Tools::displayError('You cannot edit this cart rule.'); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::getValue('submitNewVoucher') && isset($order)) { if ($this->tabAccess['edit'] === '1') { if (!Tools::getValue('discount_name')) { $this->errors[] = Tools::displayError('You must specify a name in order to create a new discount.'); } else { if ($order->hasInvoice()) { // If the discount is for only one invoice if (!Tools::isSubmit('discount_all_invoices')) { $order_invoice = new OrderInvoice(Tools::getValue('discount_invoice')); if (!Validate::isLoadedObject($order_invoice)) { throw new PrestaShopException('Can\'t load Order Invoice object'); } } } $cart_rules = array(); $discount_value = (double) str_replace(',', '.', Tools::getValue('discount_value')); switch (Tools::getValue('discount_type')) { // Percent type case 1: if ($discount_value < 100) { if (isset($order_invoice)) { $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($order_invoice->total_paid_tax_incl * $discount_value / 100, 2); $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($order_invoice->total_paid_tax_excl * $discount_value / 100, 2); // Update OrderInvoice $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']); } elseif ($order->hasInvoice()) { $order_invoices_collection = $order->getInvoicesCollection(); foreach ($order_invoices_collection as $order_invoice) { $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($order_invoice->total_paid_tax_incl * $discount_value / 100, 2); $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($order_invoice->total_paid_tax_excl * $discount_value / 100, 2); // Update OrderInvoice $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']); } } else { $cart_rules[0]['value_tax_incl'] = Tools::ps_round($order->total_paid_tax_incl * $discount_value / 100, 2); $cart_rules[0]['value_tax_excl'] = Tools::ps_round($order->total_paid_tax_excl * $discount_value / 100, 2); } } else { $this->errors[] = Tools::displayError('The discount value is invalid.'); } break; // Amount type // Amount type case 2: if (isset($order_invoice)) { if ($discount_value > $order_invoice->total_paid_tax_incl) { $this->errors[] = Tools::displayError('The discount value is greater than the order invoice total.'); } else { $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($discount_value, 2); $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($discount_value / (1 + $order->getTaxesAverageUsed() / 100), 2); // Update OrderInvoice $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']); } } elseif ($order->hasInvoice()) { $order_invoices_collection = $order->getInvoicesCollection(); foreach ($order_invoices_collection as $order_invoice) { if ($discount_value > $order_invoice->total_paid_tax_incl) { $this->errors[] = Tools::displayError('The discount value is greater than the order invoice total.') . $order_invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int) $order->id_shop) . ')'; } else { $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($discount_value, 2); $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($discount_value / (1 + $order->getTaxesAverageUsed() / 100), 2); // Update OrderInvoice $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']); } } } else { if ($discount_value > $order->total_paid_tax_incl) { $this->errors[] = Tools::displayError('The discount value is greater than the order total.'); } else { $cart_rules[0]['value_tax_incl'] = Tools::ps_round($discount_value, 2); $cart_rules[0]['value_tax_excl'] = Tools::ps_round($discount_value / (1 + $order->getTaxesAverageUsed() / 100), 2); } } break; // Free shipping type // Free shipping type case 3: if (isset($order_invoice)) { if ($order_invoice->total_shipping_tax_incl > 0) { $cart_rules[$order_invoice->id]['value_tax_incl'] = $order_invoice->total_shipping_tax_incl; $cart_rules[$order_invoice->id]['value_tax_excl'] = $order_invoice->total_shipping_tax_excl; // Update OrderInvoice $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']); } } elseif ($order->hasInvoice()) { $order_invoices_collection = $order->getInvoicesCollection(); foreach ($order_invoices_collection as $order_invoice) { if ($order_invoice->total_shipping_tax_incl <= 0) { continue; } $cart_rules[$order_invoice->id]['value_tax_incl'] = $order_invoice->total_shipping_tax_incl; $cart_rules[$order_invoice->id]['value_tax_excl'] = $order_invoice->total_shipping_tax_excl; // Update OrderInvoice $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']); } } else { $cart_rules[0]['value_tax_incl'] = $order->total_shipping_tax_incl; $cart_rules[0]['value_tax_excl'] = $order->total_shipping_tax_excl; } break; default: $this->errors[] = Tools::displayError('The discount type is invalid.'); } $res = true; foreach ($cart_rules as &$cart_rule) { $cartRuleObj = new CartRule(); $cartRuleObj->date_from = date('Y-m-d H:i:s', strtotime('-1 hour', strtotime($order->date_add))); $cartRuleObj->date_to = date('Y-m-d H:i:s', strtotime('+1 hour')); $cartRuleObj->name[Configuration::get('PS_LANG_DEFAULT')] = Tools::getValue('discount_name'); $cartRuleObj->quantity = 0; $cartRuleObj->quantity_per_user = 1; if (Tools::getValue('discount_type') == 1) { $cartRuleObj->reduction_percent = $discount_value; } elseif (Tools::getValue('discount_type') == 2) { $cartRuleObj->reduction_amount = $cart_rule['value_tax_excl']; } elseif (Tools::getValue('discount_type') == 3) { $cartRuleObj->free_shipping = 1; } $cartRuleObj->active = 0; if ($res = $cartRuleObj->add()) { $cart_rule['id'] = $cartRuleObj->id; } else { break; } } if ($res) { foreach ($cart_rules as $id_order_invoice => $cart_rule) { // Create OrderCartRule $order_cart_rule = new OrderCartRule(); $order_cart_rule->id_order = $order->id; $order_cart_rule->id_cart_rule = $cart_rule['id']; $order_cart_rule->id_order_invoice = $id_order_invoice; $order_cart_rule->name = Tools::getValue('discount_name'); $order_cart_rule->value = $cart_rule['value_tax_incl']; $order_cart_rule->value_tax_excl = $cart_rule['value_tax_excl']; $res &= $order_cart_rule->add(); $order->total_discounts += $order_cart_rule->value; $order->total_discounts_tax_incl += $order_cart_rule->value; $order->total_discounts_tax_excl += $order_cart_rule->value_tax_excl; $order->total_paid -= $order_cart_rule->value; $order->total_paid_tax_incl -= $order_cart_rule->value; $order->total_paid_tax_excl -= $order_cart_rule->value_tax_excl; } // Update Order $res &= $order->update(); } if ($res) { Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token); } else { $this->errors[] = Tools::displayError('An error occurred during the OrderCartRule creation'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } parent::postProcess(); }
public function __construct($id_product = NULL, $full = false, $id_lang = NULL) { parent::__construct($id_product, $id_lang); if ($full and $this->id) { $this->manufacturer_name = Manufacturer::getNameById(intval($this->id_manufacturer)); $this->supplier_name = Supplier::getNameById(intval($this->id_supplier)); $tax = new Tax(intval($this->id_tax), intval($id_lang)); $this->tax_name = $tax->name; $this->tax_rate = floatval($tax->rate); $this->new = $this->isNew(); } if ($this->id_category_default) { $this->category = Category::getLinkRewrite(intval($this->id_category_default), intval($id_lang)); } if ($this->id) { $this->tags = Tag::getProductTags(intval($this->id)); } }
private function getItemXML($product, $lang, $id_curr, $id_shop, $combination = false) { $xml_googleshopping = ''; $id_lang = (int) $lang['id_lang']; $title_limit = 70; $description_limit = 4990; $languages = Language::getLanguages(); $tailleTabLang = sizeof($languages); $this->context->language->id = $id_lang; $this->context->shop->id = $id_shop; $p = new Product($product['id_product'], true, $id_lang, $id_shop, $this->context); // Get module configuration for this shop if (!$combination) { $product['quantity'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], 0, $id_shop); } // Exclude non-available products if ($this->module_conf['export_nap'] === 0 && $product['quantity'] < 1) { $this->nb_not_exported_products++; return; } // Check minimum product price $price = Product::getPriceStatic((int) $product['id_product'], true); if ((double) $this->module_conf['export_min_price'] > 0 && (double) $this->module_conf['export_min_price'] > (double) $price) { return; } $cat_link_rew = Category::getLinkRewrite($product['id_gcategory'], (int) $lang); $product_link = $this->context->link->getProductLink((int) $product['id_product'], $product['link_rewrite'], $cat_link_rew, $product['ean13'], (int) $product['id_lang'], $id_shop, $combination, true); // Product name $title_crop = $product['name']; // Product color attribute, if any if (!empty($product['color'])) { $title_crop .= ' ' . $product['color']; } if (!empty($product['material'])) { $title_crop .= ' ' . $product['material']; } if (!empty($product['pattern'])) { $title_crop .= ' ' . $product['pattern']; } if (!empty($product['size'])) { $title_crop .= ' ' . $product['size']; } if (Tools::strlen($product['name']) > $title_limit) { $title_crop = Tools::substr($title_crop, 0, $title_limit - 1); $title_crop = Tools::substr($title_crop, 0, strrpos($title_crop, " ")); } // Description type if ($this->module_conf['description'] == 'long') { $description_crop = $product['description']; } else { if ($this->module_conf['description'] == 'short') { $description_crop = $product['description_short']; } else { if ($this->module_conf['description'] == 'meta') { $description_crop = $product['meta_description']; } } } $description_crop = $this->rip_tags($description_crop); if (Tools::strlen($description_crop) > $description_limit) { $description_crop = Tools::substr($description_crop, 0, $description_limit - 1); $description_crop = Tools::substr($description_crop, 0, strrpos($description_crop, " ")) . ' ...'; } $xml_googleshopping .= '<item>' . "\n"; $xml_googleshopping .= '<g:id>' . $product['gid'] . '</g:id>' . "\n"; $xml_googleshopping .= '<title><![CDATA[' . $title_crop . ']]></title>' . "\n"; $xml_googleshopping .= '<description><![CDATA[' . $description_crop . ']]></description>' . "\n"; $xml_googleshopping .= '<link><![CDATA[' . htmlspecialchars($product_link, self::REPLACE_FLAGS, self::CHARSET, false) . ']]></link>' . "\n"; // Image links $images = Image::getImages($lang['id_lang'], $product['id_product'], $combination); $indexTabLang = 0; if ($tailleTabLang > 1) { while (sizeof($images) < 1 && $indexTabLang < $tailleTabLang) { if ($languages[$indexTabLang]['id_lang'] != $lang['id_lang']) { $images = Image::getImages($languages[$indexTabLang]['id_lang'], $product['id_product']); } $indexTabLang++; } } $nbimages = 0; $image_type = $this->module_conf['img_type']; if ($image_type == '') { $image_type = 'large_default'; } foreach ($images as $im) { $image = $this->context->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $im['id_image'], $image_type); $image = preg_replace('*http://' . Tools::getHttpHost() . '/*', $this->uri, $image); if ($im['cover'] == 1) { $xml_googleshopping .= '<g:image_link><![CDATA[' . $image . ']]></g:image_link>' . "\n"; } else { $xml_googleshopping .= '<g:additional_image_link><![CDATA[' . $image . ']]></g:additional_image_link>' . "\n"; } // max images by product if (++$nbimages == 10) { break; } } // Product condition, or category's condition attribute, or its parent one... // Product condition = new, used, refurbished if (empty($product['condition'])) { $product['condition'] = $this->categories_values[$product['id_gcategory']]['gcat_condition']; } if (!empty($product['condition'])) { $xml_googleshopping .= '<g:condition><![CDATA[' . $product['condition'] . ']]></g:condition>' . "\n"; } // Shop category $breadcrumb = GCategories::getPath($product['id_gcategory'], '', $id_lang, $id_shop, $this->id_root); $product_type = ''; if (!empty($this->module_conf['product_type[]'][$id_lang])) { $product_type = $this->module_conf['product_type[]'][$id_lang]; if (!empty($breadcrumb)) { $product_type .= " > "; } } $product_type .= $breadcrumb; $xml_googleshopping .= '<g:product_type><![CDATA[' . $product_type . ']]></g:product_type>' . "\n"; // Matching Google category, or parent categories' one $product['gcategory'] = $this->categories_values[$product['category_default']]['gcategory']; $xml_googleshopping .= '<g:google_product_category><![CDATA[' . $product['gcategory'] . ']]></g:google_product_category>' . "\n"; // Product quantity & availability if (empty($this->categories_values[$product['category_default']]['gcat_avail'])) { if ($this->module_conf['quantity'] == 1) { $xml_googleshopping .= '<g:quantity>' . $product['quantity'] . '</g:quantity>' . "\n"; } if ($product['quantity'] > 0 && $product['available_for_order']) { $xml_googleshopping .= '<g:availability>in stock</g:availability>' . "\n"; } elseif ($p->isAvailableWhenOutOfStock((int) $p->out_of_stock) && $product['available_for_order']) { $xml_googleshopping .= '<g:availability>preorder</g:availability>' . "\n"; } else { $xml_googleshopping .= '<g:availability>out of stock</g:availability>' . "\n"; } } else { if ($this->module_conf['quantity'] == 1 && $product['quantity'] > 0) { $xml_googleshopping .= '<g:quantity>' . $product['quantity'] . '</g:quantity>' . "\n"; } $xml_googleshopping .= '<g:availability>' . $this->categories_values[$product['category_default']]['gcat_avail'] . '</g:availability>' . "\n"; } // Price(s) $currency = new Currency((int) $id_curr); $use_tax = $product['tax_included'] ? true : false; $no_tax = !$use_tax ? true : false; $product['price'] = (double) $p->getPriceStatic($product['id_product'], $use_tax, $combination) * $currency->conversion_rate; $product['price_without_reduct'] = (double) $p->getPriceWithoutReduct($no_tax, $combination) * $currency->conversion_rate; $product['price'] = number_format(round($product['price'], 2, PHP_ROUND_HALF_DOWN), 2, '.', ' '); $product['price_without_reduct'] = number_format(round($product['price_without_reduct'], 2, PHP_ROUND_HALF_DOWN), 2, '.', ' '); if ((double) $product['price'] < (double) $product['price_without_reduct']) { $xml_googleshopping .= '<g:price>' . $product['price_without_reduct'] . ' ' . $currency->iso_code . '</g:price>' . "\n"; $xml_googleshopping .= '<g:sale_price>' . $product['price'] . ' ' . $currency->iso_code . '</g:sale_price>' . "\n"; } else { $xml_googleshopping .= '<g:price>' . $product['price'] . ' ' . $currency->iso_code . '</g:price>' . "\n"; } $identifier_exists = 0; // GTIN (EAN, UPC, JAN, ISBN) if (!empty($product['ean13'])) { $xml_googleshopping .= '<g:gtin>' . $product['ean13'] . '</g:gtin>' . "\n"; $identifier_exists++; } // Brand if ($this->module_conf['no_brand'] != 0 && !empty($product['id_manufacturer'])) { $xml_googleshopping .= '<g:brand><![CDATA[' . htmlspecialchars(Manufacturer::getNameById((int) $product['id_manufacturer']), self::REPLACE_FLAGS, self::CHARSET, false) . ']]></g:brand>' . "\n"; $identifier_exists++; } // MPN if (empty($product['supplier_reference'])) { $product['supplier_reference'] = ProductSupplier::getProductSupplierReference($product['id_product'], 0, $product['id_supplier']); } if ($this->module_conf['mpn_type'] == 'reference' && !empty($product['reference'])) { $xml_googleshopping .= '<g:mpn><![CDATA[' . $product['reference'] . ']]></g:mpn>' . "\n"; $identifier_exists++; } else { if ($this->module_conf['mpn_type'] == 'supplier_reference' && !empty($product['supplier_reference'])) { $xml_googleshopping .= '<g:mpn><![CDATA[' . $product['supplier_reference'] . ']]></g:mpn>' . "\n"; $identifier_exists++; } } // Tag "identifier_exists" if ($this->module_conf['id_exists_tag'] && $identifier_exists < 2) { $xml_googleshopping .= '<g:identifier_exists>FALSE</g:identifier_exists>' . "\n"; } // Product gender and age_group attributes association $product_features = $this->getProductFeatures($product['id_product'], $id_lang, $id_shop); $product['gender'] = $this->categories_values[$product['category_default']]['gcat_gender']; $product['age_group'] = $this->categories_values[$product['category_default']]['gcat_age_group']; foreach ($product_features as $feature) { switch ($feature['id_feature']) { case $this->module_conf['gender']: $product['gender'] = $feature['value']; continue 2; case $this->module_conf['age_group']: $product['age_group'] = $feature['value']; continue 2; } if (!$product['color']) { foreach ($this->module_conf['color[]'] as $id => $v) { if ($v == $feature['id_feature']) { $product['color'] = $feature['value']; } } } if (!$product['material']) { foreach ($this->module_conf['material[]'] as $id => $v) { if ($v == $feature['id_feature']) { $product['material'] = $feature['value']; } } } if (!$product['pattern']) { foreach ($this->module_conf['pattern[]'] as $id => $v) { if ($v == $feature['id_feature']) { $product['pattern'] = $feature['value']; } } } if (!$product['size']) { foreach ($this->module_conf['size[]'] as $id => $v) { if ($v == $feature['id_feature']) { $product['size'] = $feature['value']; } } } } // Product gender attribute, or category gender attribute, or parent's one if (!empty($product['gender'])) { $xml_googleshopping .= '<g:gender><![CDATA[' . $product['gender'] . ']]></g:gender>' . "\n"; } // Product age_group attribute, or category age_group attribute, or parent's one if (!empty($product['age_group'])) { $xml_googleshopping .= '<g:age_group><![CDATA[' . $product['age_group'] . ']]></g:age_group>' . "\n"; } // Product attributes combination groups if ($combination && !empty($product['item_group_id'])) { $xml_googleshopping .= '<g:item_group_id>' . $product['item_group_id'] . '</g:item_group_id>' . "\n"; } // Product color attribute, or category color attribute, or parent's one if (!empty($product['color'])) { $xml_googleshopping .= '<g:color><![CDATA[' . $product['color'] . ']]></g:color>' . "\n"; } // Product material attribute, or category material attribute, or parent's one if (!empty($product['material'])) { $xml_googleshopping .= '<g:material><![CDATA[' . $product['material'] . ']]></g:material>' . "\n"; } // Product pattern attribute, or category pattern attribute, or parent's one if (!empty($product['pattern'])) { $xml_googleshopping .= '<g:pattern><![CDATA[' . $product['pattern'] . ']]></g:pattern>' . "\n"; } // Product size attribute, or category size attribute, or parent's one if (!empty($product['size'])) { $xml_googleshopping .= '<g:size><![CDATA[' . $product['size'] . ']]></g:size>' . "\n"; } // Featured products if ($this->module_conf['featured_products'] == 1 && $product['on_sale'] != '0') { $xml_googleshopping .= '<g:featured_product>true</g:featured_product>' . "\n"; } // Shipping $xml_googleshopping .= '<g:shipping>' . "\n"; $xml_googleshopping .= "\t" . '<g:country>' . $this->module_conf['shipping_country'] . '</g:country>' . "\n"; $xml_googleshopping .= "\t" . '<g:service>Standard</g:service>' . "\n"; $xml_googleshopping .= "\t" . '<g:price>' . number_format($this->module_conf['shipping_price'], 2, '.', ' ') . ' ' . $currency->iso_code . '</g:price>' . "\n"; $xml_googleshopping .= '</g:shipping>' . "\n"; // Shipping weight if ($product['weight'] != '0') { $xml_googleshopping .= '<g:shipping_weight>' . number_format($product['weight'], 2, '.', '') . ' ' . Configuration::get('PS_WEIGHT_UNIT') . '</g:shipping_weight>' . "\n"; } $xml_googleshopping .= '</item>' . "\n\n"; if ($combination) { $this->nb_combinations++; $this->nb_prd_w_attr[$product['id_product']] = 1; } $this->nb_total_products++; return $xml_googleshopping; }
private function generateFile($lang) { $path_parts = pathinfo(__FILE__); if (Configuration::get('GENERATE_FILE_IN_ROOT')) { $generate_file_path = dirname(__FILE__) . '/../../' . $this->_getOutputFileName($lang['iso_code']); } else { $generate_file_path = dirname(__FILE__) . '/file_exports/' . $this->_getOutputFileName($lang['iso_code']); } //Google Shopping XML $xml = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n"; $xml .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0" encoding="UTF-8" >' . "\n"; $xml .= '<title>' . Configuration::get('PS_SHOP_NAME') . '</title>' . "\n"; $xml .= '<link href="' . htmlspecialchars($this->uri, self::REPLACE_FLAGS, self::CHARSET, false) . '" rel="alternate" type="text/html"/>' . "\n"; $xml .= '<modified>' . date('Y-m-d') . 'T01:01:01Z</modified><author><name>' . Configuration::get('PS_SHOP_NAME') . '</name></author>' . "\n"; $googleshoppingfile = fopen($generate_file_path, 'w'); // add UTF-8 byte order mark fwrite($googleshoppingfile, pack("CCC", 0xef, 0xbb, 0xbf)); //file header fwrite($googleshoppingfile, $xml); $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'product p' . ' LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON p.id_product = pl.id_product' . ' WHERE p.active = 1 AND pl.id_lang=' . $lang['id_lang']; $products = Db::getInstance()->ExecuteS($sql); $title_limit = 70; $description_limit = 10000; $languages = Language::getLanguages(); $tailleTabLang = sizeof($languages); foreach ($products as $product) { $xml_googleshopping = ''; $cat_link_rew = Category::getLinkRewrite($product['id_category_default'], intval($lang)); //continue if product not have price $price = Product::getPriceStatic($product['id_product'], true, NULL, 2); if (empty($price)) { continue; } $product_link = $this->context->link->getProductLink((int) $product['id_product'], $product['link_rewrite'], $cat_link_rew, $product['ean13'], (int) $product['id_lang'], 1, 0, true); $title_crop = $product['name']; if (strlen($product['name']) > $title_limit) { $title_crop = substr($title_crop, 0, $title_limit - 1); $title_crop = substr($title_crop, 0, strrpos($title_crop, " ")); } if (intval(Configuration::get('DESCRIPTION')) === intval(2)) { $description_crop = $product['description']; } else { $description_crop = $product['description_short']; } $description_crop = $this->rip_tags($description_crop); if (strlen($description_crop) > $description_limit) { $description_crop = substr($description_crop, 0, $description_limit - 1); $description_crop = substr($description_crop, 0, strrpos($description_crop, " ")); } $xml_googleshopping .= '<entry>' . "\n"; $xml_googleshopping .= '<g:id>' . $product['id_product'] . '-' . $lang['iso_code'] . '</g:id>' . "\n"; $xml_googleshopping .= '<title>' . htmlentities(ucfirst(mb_strtolower($title_crop, self::CHARSET)), self::REPLACE_FLAGS, self::CHARSET) . '</title>' . "\n"; $xml_googleshopping .= '<link>' . htmlspecialchars($product_link, self::REPLACE_FLAGS, self::CHARSET, false) . '</link>' . "\n"; $xml_googleshopping .= '<g:price>' . $price . '</g:price>' . "\n"; $xml_googleshopping .= '<g:description>' . htmlentities($description_crop, self::REPLACE_FLAGS, self::CHARSET) . '</g:description>' . "\n"; $xml_googleshopping .= '<g:condition>new</g:condition>' . "\n"; // condition = new, used, refurbished $images = Image::getImages($lang['id_lang'], $product['id_product']); $indexTabLang = 0; if ($tailleTabLang > 1) { while (sizeof($images) < 1 && $indexTabLang < $tailleTabLang) { if ($languages[$indexTabLang]['id_lang'] != $lang['id_lang']) { $images = Image::getImages($languages[$indexTabLang]['id_lang'], $product['id_product']); } $indexTabLang++; } } $nbimages = 0; $image_type = Configuration::get('GS_IMAGE'); if ($image_type == '') { $image_type = 'large_default'; } /* create image links */ foreach ($images as $im) { $image = $this->context->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $im['id_image'], $image_type); $xml_googleshopping .= '<g:image_link>' . $image . '</g:image_link>' . "\n"; //max images by product if (++$nbimages == 10) { break; } } if (Configuration::get('QUANTITY') == 1) { $quantity = StockAvailable::getQuantityAvailableByProduct($product['id_product'], 0); if ($quantity > 0) { $xml_googleshopping .= '<g:quantity>' . $quantity . '</g:quantity>' . "\n"; $xml_googleshopping .= '<g:availability>in stock</g:availability>' . "\n"; } else { $xml_googleshopping .= '<g:quantity>0</g:quantity>' . "\n"; $xml_googleshopping .= '<g:availability>out of stock</g:availability>' . "\n"; } } // Brand $identifier_exists = false; if (Configuration::get('BRAND') && $product['id_manufacturer'] != '0') { $xml_googleshopping .= '<g:brand>' . htmlspecialchars(Manufacturer::getNameById(intval($product['id_manufacturer'])), self::REPLACE_FLAGS, self::CHARSET, false) . '</g:brand>' . "\n"; $identifier_exists = true; } if (Configuration::get('MPN') && $product['supplier_reference'] != '') { $xml_googleshopping .= '<g:mpn>' . $product['supplier_reference'] . '</g:mpn>'; $identifier_exists = true; } if (Configuration::get('GTIN') && $product['ean13'] != '') { $xml_googleshopping .= '<g:gtin>' . $product['ean13'] . '</g:gtin>' . "\n"; $identifier_exists = true; } if (!$identifier_exists) { $xml_googleshopping .= '<g:identifier_exists>FALSE</g:identifier_exists>' . "\n"; } // Category google if (Configuration::get('GS_PRODUCT_TYPE_' . $lang['iso_code'])) { $product_type = str_replace('>', '>', Configuration::get('GS_PRODUCT_TYPE_' . $lang['iso_code'])); $product_type = str_replace('&', '&', $product_type); $xml_googleshopping .= '<g:google_product_category>' . $product_type . '</g:google_product_category>' . "\n"; } // Category shop if (Configuration::get('CATEGORY_SHOP')) { $categories = $this->getBreadcrumbCategory($product['id_category_default'], $product['id_lang']); $categories = str_replace('>', '>', $categories); $categories = str_replace('&', '&', $categories); $xml_googleshopping .= '<g:product_type>' . $categories . '</g:product_type>' . "\n"; } //Shipping $xml_googleshopping .= '<g:shipping>' . "\n"; $xml_googleshopping .= '<g:country>' . Configuration::get('GS_COUNTRY') . '</g:country>' . "\n"; $xml_googleshopping .= '<g:service>Standard</g:service>' . "\n"; $xml_googleshopping .= '<g:price>' . Configuration::get('GS_SHIPPING') . '</g:price>' . "\n"; $xml_googleshopping .= '</g:shipping>' . "\n"; //weight if ($product['weight'] != '0') { $xml_googleshopping .= '<g:shipping_weight>' . $product['weight'] . ' kilograms</g:shipping_weight>' . "\n"; } //featured product if (Configuration::get('FEATURED_PRODUCT') == 1 && $product['on_sale'] != '0') { $xml_googleshopping .= '<g:featured_product>true</g:featured_product>' . "\n"; } if (Configuration::get('GTIN') && $product['ean13'] != '') { $xml_googleshopping .= '<g:gtin>' . $product['ean13'] . '</g:gtin>' . "\n"; } $xml_googleshopping .= '</entry>' . "\n"; // Write element fwrite($googleshoppingfile, $xml_googleshopping); } $xml = '</feed>'; fwrite($googleshoppingfile, $xml); fclose($googleshoppingfile); @chmod($generate_file_path, 0777); return true; }
private static function _getEbayDescription($product, $ebay_profile, $id_lang) { $features_html = ''; foreach ($product->getFrontFeatures((int) $id_lang) as $feature) { $features_html .= '<b>' . $feature['name'] . '</b> : ' . $feature['value'] . '<br/>'; } return str_replace(array('{DESCRIPTION_SHORT}', '{DESCRIPTION}', '{FEATURES}', '{EBAY_IDENTIFIER}', '{EBAY_SHOP}', '{SLOGAN}', '{PRODUCT_NAME}', '{REFERENCE}', '{BRAND}', '{BRAND_ID}'), array($product->description_short, $product->description, $features_html, $ebay_profile->ebay_user_identifier, $ebay_profile->getConfiguration('EBAY_SHOP'), '', $product->name, $product->reference, Manufacturer::getNameById($product->id_manufacturer), $product->id_manufacturer), $ebay_profile->getConfiguration('EBAY_PRODUCT_TEMPLATE')); }
public function getWsManufacturerName() { return Manufacturer::getNameById((int) $this->id_manufacturer); }
public function __construct($id_product = NULL, $full = false, $id_lang = NULL) { global $cart; parent::__construct($id_product, $id_lang); if ($full and $this->id) { $this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode) $this->manufacturer_name = Manufacturer::getNameById(intval($this->id_manufacturer)); $this->supplier_name = Supplier::getNameById(intval($this->id_supplier)); $tax = new Tax(intval($this->id_tax)); if (is_object($cart) and $cart->id_address_delivery != NULL) { $this->tax_rate = Tax::getApplicableTax(intval($this->id_tax), floatval($tax->rate)); } else { $this->tax_rate = floatval($tax->rate); } $this->new = $this->isNew(); } if ($this->id_category_default) { $this->category = Category::getLinkRewrite(intval($this->id_category_default), intval($id_lang)); } if ($this->id) { $this->tags = Tag::getProductTags(intval($this->id)); } }
public function renderFormAddress() { // Change table and className for addresses $this->table = 'address'; $this->className = 'Address'; $id_address = Tools::getValue('id_address'); // Create Object Address $address = new Address($id_address); $res = $address->getFieldsRequiredDatabase(); $required_fields = array(); foreach ($res as $row) { $required_fields[(int) $row['id_required_field']] = $row['field_name']; } $form = array('legend' => array('title' => $this->l('Addresses'), 'icon' => 'icon-building')); if (!$address->id_manufacturer || !Manufacturer::manufacturerExists($address->id_manufacturer)) { $form['input'][] = array('type' => 'select', 'label' => $this->l('Choose the manufacturer'), 'name' => 'id_manufacturer', 'options' => array('query' => Manufacturer::getManufacturers(), 'id' => 'id_manufacturer', 'name' => 'name')); } else { $form['input'][] = array('type' => 'text', 'label' => $this->l('Manufacturer'), 'name' => 'name', 'col' => 4, 'disabled' => true); $form['input'][] = array('type' => 'hidden', 'name' => 'id_manufacturer'); } $form['input'][] = array('type' => 'hidden', 'name' => 'alias'); $form['input'][] = array('type' => 'hidden', 'name' => 'id_address'); if (in_array('company', $required_fields)) { $form['input'][] = array('type' => 'text', 'label' => $this->l('Company'), 'name' => 'company', 'display' => in_array('company', $required_fields), 'required' => in_array('company', $required_fields), 'maxlength' => 16, 'col' => 4, 'hint' => $this->l('Company name for this supplier')); } $form['input'][] = array('type' => 'text', 'label' => $this->l('Last name'), 'name' => 'lastname', 'required' => true, 'col' => 4, 'hint' => $this->l('Invalid characters:') . ' 0-9!<>,;?=+()@#"�{}_$%:'); $form['input'][] = array('type' => 'text', 'label' => $this->l('First name'), 'name' => 'firstname', 'required' => true, 'col' => 4, 'hint' => $this->l('Invalid characters:') . ' 0-9!<>,;?=+()@#"�{}_$%:'); $form['input'][] = array('type' => 'text', 'label' => $this->l('Address'), 'name' => 'address1', 'col' => 6, 'required' => true); $form['input'][] = array('type' => 'text', 'label' => $this->l('Address (2)'), 'name' => 'address2', 'col' => 6, 'required' => in_array('address2', $required_fields)); $form['input'][] = array('type' => 'text', 'label' => $this->l('Zip/postal code'), 'name' => 'postcode', 'col' => 2, 'required' => in_array('postcode', $required_fields)); $form['input'][] = array('type' => 'text', 'label' => $this->l('City'), 'name' => 'city', 'col' => 4, 'required' => true); $form['input'][] = array('type' => 'select', 'label' => $this->l('Country'), 'name' => 'id_country', 'required' => false, 'default_value' => (int) $this->context->country->id, 'col' => 4, 'options' => array('query' => Country::getCountries($this->context->language->id), 'id' => 'id_country', 'name' => 'name')); $form['input'][] = array('type' => 'select', 'label' => $this->l('State'), 'name' => 'id_state', 'required' => false, 'col' => 4, 'options' => array('query' => array(), 'id' => 'id_state', 'name' => 'name')); $form['input'][] = array('type' => 'text', 'label' => $this->l('Home phone'), 'name' => 'phone', 'col' => 4, 'required' => in_array('phone', $required_fields)); $form['input'][] = array('type' => 'text', 'label' => $this->l('Mobile phone'), 'name' => 'phone_mobile', 'col' => 4, 'required' => in_array('phone_mobile', $required_fields)); $form['input'][] = array('type' => 'textarea', 'label' => $this->l('Other'), 'name' => 'other', 'required' => false, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}', 'rows' => 2, 'cols' => 10, 'col' => 6); $form['submit'] = array('title' => $this->l('Save')); $this->fields_value = array('name' => Manufacturer::getNameById($address->id_manufacturer), 'alias' => 'manufacturer', 'id_country' => $address->id_country); $this->initToolbar(); $this->fields_form[0]['form'] = $form; $this->getlanguages(); $helper = new HelperForm(); $helper->show_cancel_button = true; $back = Tools::safeOutput(Tools::getValue('back', '')); if (empty($back)) { $back = self::$currentIndex . '&token=' . $this->token; } if (!Validate::isCleanHtml($back)) { die(Tools::displayError()); } $helper->back_url = $back; $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = $this->table; $helper->identifier = $this->identifier; $helper->title = $this->l('Edit Addresses'); $helper->id = $address->id; $helper->toolbar_scroll = true; $helper->languages = $this->_languages; $helper->default_form_language = $this->default_form_language; $helper->allow_employee_form_lang = $this->allow_employee_form_lang; $helper->fields_value = $this->getFieldsValue($address); $helper->toolbar_btn = $this->toolbar_btn; $this->content .= $helper->generateForm($this->fields_form); }
public function __construct($id_product = NULL, $full = false, $id_lang = NULL) { global $cart; parent::__construct($id_product, $id_lang); if ($full and $this->id) { $this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode) $this->manufacturer_name = Manufacturer::getNameById((int) $this->id_manufacturer); $this->supplier_name = Supplier::getNameById((int) $this->id_supplier); self::$_tax_rules_group[$this->id] = $this->id_tax_rules_group; if (is_object($cart) and $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != NULL) { $this->tax_rate = Tax::getProductTaxRate($this->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } else { $this->tax_rate = Tax::getProductTaxRate($this->id, NULL); } $this->new = $this->isNew(); $this->price = Product::getPriceStatic((int) $this->id, false, NULL, 6, NULL, false, true, 1, false, NULL, NULL, NULL, $this->specificPrice); $this->unit_price = $this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0; if ($this->id) { $this->tags = Tag::getProductTags((int) $this->id); } } if ($this->id_category_default) { $this->category = Category::getLinkRewrite((int) $this->id_category_default, (int) $id_lang); } }
/** * @param Product $product to get the product properties * @param array $combination to get particular properties from a declination * @param int $lang id lang to take all text in good language * @param Link $link to set the link of the product and its images. * @param Carrier $carrier not used now, but usable for next version, needed for calculate the shipping cost, * But for now it's not sure enough. * @return array with good value for the XML. */ private function preparedValues(Product $product, $combination, $lang, Link $link, Carrier $carrier) { $arr_return = array(); $str_features = array(); $model = array(); $version = str_replace('.', '', _PS_VERSION_); // To build description and model tags. if (isset($combination['attributes'])) { foreach ($combination['attributes'] as $attribut) { $str_features[] = $attribut['group_name'] . ' : ' . $attribut['name']; $model[] = $attribut['name']; } } if (isset($combination['weight']) && (int) $combination['weight'] !== 0) { $str_features[] = 'weight : ' . $combination['weight']; } elseif ($product->weight !== 0) { $str_features[] = 'weight : ' . $product->weight; } $features = $product->getFrontFeatures($lang); foreach ($features as $feature) { $str_features[] = $feature['name'] . ' : ' . $feature['value']; } // Category tag $category = new Category((int) $product->id_category_default, $lang); $category_path = (isset($category->id) and $category->id) ? Tools::getFullPath((int) $category->id, $product->name[$lang]) : Tools::getFullPath((int) $product->id_category_default, $product->name[$lang]); $category_path = Configuration::get('PS_NAVIGATION_PIPE') != false && Configuration::get('PS_NAVIGATION_PIPE') !== '>' ? str_replace(Configuration::get('PS_NAVIGATION_PIPE'), '>', $category_path) : $category_path; // image tag $id_image = isset($combination['id_image']) ? $combination['id_image'] : 0; if ($id_image === 0 || $id_image < 0) { $image = $product->getCover((int) $product->id); $id_image = $image['id_image']; } $quantity = Product::getQuantity($product->id, isset($combination['id_combination']) ? $combination['id_combination'] : NULL); $condition = ''; if (strlen((string) $version) < 2) { $version = (string) $version . '0'; } if ((int) substr($version, 0, 2) >= 14) { $condition = $product->condition === 'new' ? 0 : 1; } $price = $product->getPrice(true, isset($combination['id_combination']) ? $combination['id_combination'] : NULL, 2); $upc_ean = strlen((string) $product->ean13) == 13 ? $product->ean13 : ''; $arr_return['product_url'] = $link->getProductLink((int) $product->id, $product->link_rewrite[$lang], $product->ean13, $lang); $arr_return['designation'] = Tools::htmlentitiesUTF8($product->name[$lang] . ' ' . Manufacturer::getNameById($product->id_manufacturer) . ' ' . implode(' ', $model)); $arr_return['price'] = $price; $arr_return['category'] = Tools::htmlentitiesUTF8(strip_tags($category_path)); if (substr(_PS_VERSION_, 0, 3) == '1.3') { if (!Configuration::get('PS_SHOP_DOMAIN')) { Configuration::updateValue('PS_SHOP_DOMAIN', $_SERVER['HTTP_HOST']); } $prefix = 'http://' . Configuration::get('PS_SHOP_DOMAIN') . '/'; $arr_return['image_url'] = $prefix . $link->getImageLink('', $product->id . '-' . $id_image, 'large'); } else { $arr_return['image_url'] = $link->getImageLink($product->link_rewrite[$lang], $product->id . '-' . $id_image, 'large'); } // Must description added since Twenga-module v1.1 $arr_return['description'] = is_array($product->description) ? strip_tags($product->description[$lang]) : strip_tags($product->description); $arr_return['description'] = trim($arr_return['description'] . ' ' . strip_tags(implode(', ', $str_features))); $arr_return['description'] = Tools::htmlentitiesUTF8($arr_return['description']); $arr_return['brand'] = Manufacturer::getNameById($product->id_manufacturer); $arr_return['merchant_id'] = $product->id; $arr_return['manufacturer_id'] = $product->id_manufacturer; $arr_return['shipping_cost'] = 'NC'; $arr_return['in_stock'] = $quantity > 0 ? 'Y' : 'N'; $arr_return['stock_detail'] = $quantity; $arr_return['condition'] = $condition; $arr_return['upc_ean'] = $upc_ean; $arr_return['eco_tax'] = $product->ecotax; // for prestashop 1.4 and previous version these fields are not managed. // So default values are set. $arr_return['product_type'] = '1'; $arr_return['isbn'] = ''; return $arr_return; }
public function __construct($id_product = NULL, $full = false, $id_lang = NULL) { parent::__construct($id_product, $id_lang); if ($full and $this->id) { $this->manufacturer_name = Manufacturer::getNameById(intval($this->id_manufacturer)); $this->supplier_name = Supplier::getNameById(intval($this->id_supplier)); if (!class_exists("Vendor", false)) { include_once dirname(__FILE__) . '/../modules/ordervendor/Vendor.php'; } $this->vendor_name = Vendor::getNameById(intval($this->id_vendor)); } $this->category = Category::getLinkRewrite(intval($this->id_category_default), intval($id_lang)); $this->tags = Tag::getProductTags($this->id); }