本文整理汇总了PHP中Tools::link_rewrite方法的典型用法代码示例。如果您正苦于以下问题:PHP Tools::link_rewrite方法的具体用法?PHP Tools::link_rewrite怎么用?PHP Tools::link_rewrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tools
的用法示例。
在下文中一共展示了Tools::link_rewrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: displayContent
public function displayContent($params)
{
$alias_shop = (int) Tools::getValue('ash');
if (!empty($alias_shop)) {
$_s = AphStore::getByAlias($alias_shop, Context::getContext()->language->id);
$id_shop = $_s['id_shop'];
} else {
$id_shop = (int) Tools::getValue('ids');
}
$shop = new AphStore($id_shop, Context::getContext()->language->id);
$this->nbOffers = AphOffer::getOffers('store', $id_shop, Context::getContext()->language->id, true, NULL, (int) Configuration::get('APH_OFFERS_PER_PAGE'), $this->orderBy, $this->orderWay, true);
$this->pagination((int) $this->nbOffers);
// Pagination must be call after "getStoresByProduct"
$this->offerSort();
$id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT');
$offers = AphOffer::getOffers('store', $id_shop, Context::getContext()->language->id, true, NULL, (int) Configuration::get('APH_OFFERS_PER_PAGE'), $this->orderBy, $this->orderWay);
foreach ($offers as &$offer) {
$offer = new AphOffer($offer['id_offer'], (int) Context::getContext()->language->id, (int) $id_shop);
$offer['price_from'] = Tools::displayPrice($offer->price_wt, $id_currency);
error_log($o->reduction . ' ' . $o->id);
$offer['new_price'] = $o->price_wt < 0 ? $o->reduction_type == 'percentage' ? '-' . intval(round($o->reduction)) . '%' : '-' . Tools::displayPrice($o['reduction'], (int) Context::getContext()->currency->id) : Tools::displayPrice($o->price_wt, (int) Context::getContext()->currency->id) . ' ';
$offer['url'] = Context::getContext()->link->getModuleLink('blockoffers', 'offer', array('aof' => $offer['link_rewrite'], 'ido' => $offer['id_offer']));
$offer['img_link_rewrite'] = Tools::link_rewrite($offer['legend']);
}
$this->context->smarty->assign(array('offers' => $offers, 'nb_offers' => $this->nbOffers));
$this->context->controller->addJS($this->_path . 'blockoffer.js');
return $this->display(__FILE__, 'blockoffers.tpl', $this->getCacheId());
}
示例2: getIsoCodeByFolderName
/**
* Permet de récupérer le code_iso d'une langue à partir d'un nom de dossier
* @param string $sFolderName
* @return array
*/
public static function getIsoCodeByFolderName($sFolderName)
{
$sSQL = '
SELECT l.`iso_code`
FROM `' . _DB_PREFIX_ . 'now_language_link` ll
' . Shop::addSqlAssociation('now_language_link', 'll') . '
INNER JOIN `' . _DB_PREFIX_ . 'lang` l ON (l.`id_lang` = ll.`id_lang`)
WHERE ll.`folder_name` = "' . Tools::link_rewrite($sFolderName) . '"';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sSQL);
return $result;
}
示例3: initContent
public function initContent()
{
parent::initContent();
$shop = NULL;
$alias_offer = (int) Tools::getValue('aof');
if (!empty($alias_offer)) {
$_o = AphOffer::getByAlias($alias_offer, Context::getContext()->language->id);
$id_offer = $_o['id_offer'];
} else {
$id_offer = (int) Tools::getValue('ido');
}
$offer = new AphOffer($id_offer, Context::getContext()->language->id);
$offer->new_price = $offer->price_wt < 0 ? $offer->reduction_type == 'percentage' ? '-' . intval($offer->reduction * 100) . '%' : '-' . Tools::displayPrice($offer['reduction'], (int) Context::getContext()->currency->id) : Tools::displayPrice($offer->price_wt, (int) Context::getContext()->currency->id) . ' ';
$cover = NULL;
$images = AphOfferImage::getImages(Context::getContext()->language->id, $id_offer);
foreach ($images as &$image) {
if (!empty($image['cover'])) {
$cover = $image;
}
}
if (empty($cover) && !empty($images)) {
$cover = $images[0];
}
$this->context->smarty->tpl_vars['meta_title']->value = $offer->name;
$this->context->smarty->tpl_vars['meta_description']->value = $offer->meta_description;
$shops = AphOffer::getShopsLight(Context::getContext()->language->id, $offer->id);
foreach ($shops as &$shop) {
$shop['link'] = Context::getContext()->link->getModuleLink('blockshops', 'shop', array('ash' => $shop['uri'], 'ids' => $shop['id_shop']));
}
/*$products = AphOffer::getProductsLight(Context::getContext()->language->id, $offer->id);
foreach ($products as &$product) {
$product['link'] = Context::getContext()->link->getProductLink((int)$product['id_product'], $product['link_rewrite']);
}*/
$products_by_category = array();
$ps = AphOffer::getProductsLight(Context::getContext()->language->id, $offer->id);
foreach ($ps as &$p) {
$product = new Product($p['id_product'], false, Context::getContext()->language->id);
$category = new Category($product->id_category_default, Context::getContext()->language->id);
if (empty($products_by_category[$category->id])) {
$products_by_category[$category->id] = array('id_category' => $category->id, 'name' => $category->name, 'class' => Tools::link_rewrite($category->name), 'products' => array());
}
$products_by_category[$category->id]['products'][$product->id] = array('id_product' => $product->id, 'name' => $product->name, 'link' => Context::getContext()->link->getProductLink((int) $product->id, $product->link_rewrite, $category->id, $product->ean13));
}
$this->context->smarty->assign(array('offer' => $offer, 'cover' => $cover, 'images' => $images, 'shops' => $shops, 'products_by_category' => $products_by_category));
$this->setTemplate('offer.tpl');
}
示例4: initContent
public function initContent()
{
parent::initContent();
$shop = NULL;
$alias_shop = (int) Tools::getValue('ash');
if (!empty($alias_shop)) {
$_s = AphStore::getByAlias($alias_shop, Context::getContext()->language->id);
$id_shop = $_s['id_shop'];
} else {
$id_shop = (int) Tools::getValue('ids');
}
$shop = new AphStore($id_shop, Context::getContext()->language->id);
$cover = NULL;
$images = AphStoreImage::getImages(Context::getContext()->language->id, $id_shop);
foreach ($images as &$image) {
if (!empty($image['cover'])) {
$cover = $image;
}
}
if (empty($cover) && !empty($images)) {
$cover = $images[0];
}
$this->context->smarty->tpl_vars['meta_title']->value = $shop->name;
$this->context->smarty->tpl_vars['meta_description']->value = $shop->meta_description;
$products_by_category = array();
$categories = Category::getAllCategoriesName(NULL, Context::getContext()->language->id, true);
if (!empty($categories)) {
foreach ($categories as &$category) {
if (Configuration::get('PS_ROOT_CATEGORY') == $category['id_category'] || Configuration::get('PS_HOME_CATEGORY') == $category['id_category']) {
continue;
}
$products = AphStore::getProductsByStore($id_shop, Context::getContext()->language->id, NULL, NULL, 'name', 'desc', $category['id_category'], true);
foreach ($products as &$product) {
if (empty($products_by_category[$category['id_category']])) {
$products_by_category[$category['id_category']] = array('id_category' => $category['id_category'], 'name' => $category['name'], 'class' => Tools::link_rewrite($category['name']), 'products' => array());
}
$products_by_category[$category['id_category']]['products'][$product['id_product']] = array('id_product' => $product['id_product'], 'name' => $product['name'], 'link' => Context::getContext()->link->getProductLink((int) $product['id_product'], $product['link_rewrite'], $category['id_category'], $product['ean13']));
}
}
}
$this->context->smarty->assign(array('shop' => $shop, 'cover' => $cover, 'images' => $images, 'products_by_category' => $products_by_category));
$this->context->controller->addCSS('/themes/aphrodinet/css/shop.css', 'all');
$this->setTemplate('shop.tpl');
}
示例5: initContent
public function initContent()
{
parent::initContent();
$this->module->nbOffers = AphOffer::getOffers(NULL, NULL, Context::getContext()->language->id, true, NULL, (int) Configuration::get('APH_OFFERS_PER_PAGE'), $this->module->orderBy, $this->module->orderWay, true);
$this->module->pagination((int) $this->module->nbOffers);
// Pagination must be call after "getStoresByProduct"
$this->module->offerSort();
$id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT');
$offers = AphOffer::getOffers(NULL, NULL, Context::getContext()->language->id, true, NULL, (int) Configuration::get('APH_OFFERS_PER_PAGE'), $this->module->orderBy, $this->module->orderWay);
foreach ($offers as &$offer) {
$o = new AphOffer($offer['id_offer'], (int) Context::getContext()->language->id, (int) $id_shop);
$offer['description_short'] = $o->description_short;
$offer['available_from_date'] = $o->available_from_date;
$offer['available_to_date'] = $o->available_to_date;
$offer['price_from'] = Tools::displayPrice($o->price_wt, $id_currency);
$offer['new_price'] = $o->price_wt < 0 ? $o->reduction_type == 'percentage' ? '-' . intval(round($o->reduction)) . '%' : '-' . Tools::displayPrice($o->reduction, (int) Context::getContext()->currency->id) : Tools::displayPrice($o->price_wt, (int) Context::getContext()->currency->id) . ' ';
$offer['url'] = Context::getContext()->link->getModuleLink('blockoffers', 'offer', array('aof' => $offer['link_rewrite'], 'ido' => $offer['id_offer']));
$offer['img_link_rewrite'] = Tools::link_rewrite($offer['legend']);
}
$this->context->smarty->assign(array('offers' => $offers, 'nb_offers' => $this->module->nbOffers));
$this->context->controller->addJS('blockoffers.js');
$this->setTemplate('blockoffers.tpl');
}
示例6: generateCategoriesMenu
protected function generateCategoriesMenu($categories, $is_children = 0)
{
$html = '';
foreach ($categories as $key => $category) {
if ($category['level_depth'] > 1) {
$cat = new Category($category['id_category']);
$link = Tools::HtmlEntitiesUTF8($cat->getLink());
} else {
$link = $this->context->link->getPageLink('index');
}
/* Whenever a category is not active we shouldnt display it to customer */
if ((bool) $category['active'] === false) {
continue;
}
$html .= '<li' . ($this->page_name == 'category' && (int) Tools::getValue('id_category') == (int) $category['id_category'] ? ' class="sfHoverForce ' . Tools::link_rewrite($category['name']) . '"' : ' class="' . Tools::link_rewrite($category['name']) . '"') . '>';
$html .= '<a href="' . $link . '" title="' . $category['name'] . '"><img src="/themes/aphrodinet/img/menu-icon-' . strtolower($category['name']) . '.png" /><br/>' . $category['name'] . '</a>';
if (isset($category['children']) && !empty($category['children'])) {
$html .= '<ul>';
$html .= $this->generateCategoriesMenu($category['children'], 1);
if ((int) $category['level_depth'] > 1 && !$is_children) {
$files = scandir(_PS_CAT_IMG_DIR_);
if (count(preg_grep('/^' . $category['id_category'] . '-([0-9])?_thumb.jpg/i', $files)) > 0) {
$html .= '<li class="category-thumbnail">';
foreach ($files as $file) {
if (preg_match('/^' . $category['id_category'] . '-([0-9])?_thumb.jpg/i', $file) === 1) {
$html .= '<div><img src="' . $this->context->link->getMediaLink(_THEME_CAT_DIR_ . $file) . '" alt="' . Tools::SafeOutput($category['name']) . '" title="' . Tools::SafeOutput($category['name']) . '" class="imgm" /></div>';
}
}
$html .= '</li>';
}
}
$html .= '</ul>';
}
$html .= '</li>';
}
return $html;
}
示例7: lower
public function lower($strIn)
{
$strOut = Tools::link_rewrite($strIn);
return strtolower(str_replace('-', ' ', $strOut));
}
示例8: productImportCreateCat
public function productImportCreateCat($default_language_id, $category_name, $id_parent_category = null)
{
$category_to_create = new Category();
$shop_is_feature_active = Shop::isFeatureActive();
if (!$shop_is_feature_active) {
$category_to_create->id_shop_default = 1;
} else {
$category_to_create->id_shop_default = (int) Context::getContext()->shop->id;
}
$category_to_create->name = AdminImportController::createMultiLangField(trim($category_name));
$category_to_create->active = 1;
$category_to_create->id_parent = (int) $id_parent_category ? (int) $id_parent_category : (int) Configuration::get('PS_HOME_CATEGORY');
// Default parent is home for unknown category to create
$category_link_rewrite = Tools::link_rewrite($category_to_create->name[$default_language_id]);
$category_to_create->link_rewrite = AdminImportController::createMultiLangField($category_link_rewrite);
if (($field_error = $category_to_create->validateFields(UNFRIENDLY_ERROR, true)) !== true || ($lang_field_error = $category_to_create->validateFieldsLang(UNFRIENDLY_ERROR, true)) !== true || !$category_to_create->add()) {
$this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $category_to_create->name[$default_language_id], isset($category_to_create->id) && !empty($category_to_create->id) ? $category_to_create->id : 'null');
if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
示例9: postProcess
public function postProcess()
{
$SmartBlogPost = new SmartBlogPost();
$BlogPostCategory = new BlogPostCategory();
if (Tools::isSubmit('deletesmart_blog_post') && Tools::getValue('id_smart_blog_post') != '') {
$SmartBlogPost = new SmartBlogPost((int) Tools::getValue('id_smart_blog_post'));
if (!$SmartBlogPost->delete()) {
$this->errors[] = Tools::displayError('An error occurred while deleting the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
} else {
Hook::exec('actionsbdeletepost', array('SmartBlogPost' => $SmartBlogPost));
Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogPost'));
}
} elseif (Tools::getValue('deleteImage')) {
$this->processForceDeleteImage();
if (Tools::isSubmit('forcedeleteImage')) {
Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminBlogPost') . '&conf=7');
}
} elseif (Tools::isSubmit('submitAddsmart_blog_post')) {
parent::validateRules();
if (count($this->errors)) {
return false;
}
if (!($id_smart_blog_post = (int) Tools::getValue('id_smart_blog_post'))) {
$SmartBlogPost = new $SmartBlogPost();
$id_lang_default = Configuration::get('PS_LANG_DEFAULT');
$languages = Language::getLanguages(false);
foreach ($languages as $language) {
$title = Tools::link_rewrite(Tools::getValue('meta_title_' . $language['id_lang']));
$SmartBlogPost->meta_title[$language['id_lang']] = $title;
$SmartBlogPost->meta_keyword[$language['id_lang']] = (string) Tools::getValue('meta_keyword_' . $language['id_lang']);
$SmartBlogPost->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
$SmartBlogPost->short_description[$language['id_lang']] = (string) Tools::getValue('short_description_' . $language['id_lang']);
$SmartBlogPost->content[$language['id_lang']] = Tools::getValue('content_' . $language['id_lang']);
if (Tools::getValue('link_rewrite_' . $language['id_lang']) == '' && Tools::getValue('link_rewrite_' . $language['id_lang']) == null) {
$SmartBlogPost->link_rewrite[$language['id_lang']] = Tools::link_rewrite(Tools::getValue('meta_title_' . $id_lang_default));
} else {
$SmartBlogPost->link_rewrite[$language['id_lang']] = Tools::link_rewrite(Tools::getValue('link_rewrite_' . $language['id_lang']));
}
}
$SmartBlogPost->id_parent = Tools::getValue('id_parent');
$SmartBlogPost->position = 0;
$SmartBlogPost->active = Tools::getValue('active');
$SmartBlogPost->id_category = Tools::getValue('id_category');
$SmartBlogPost->comment_status = Tools::getValue('comment_status');
$SmartBlogPost->id_author = $this->context->employee->id;
$SmartBlogPost->created = Date('y-m-d H:i:s');
$SmartBlogPost->modified = Date('y-m-d H:i:s');
$SmartBlogPost->available = 1;
$SmartBlogPost->is_featured = Tools::getValue('is_featured');
$SmartBlogPost->viewed = 1;
$SmartBlogPost->post_type = Tools::getValue('post_type');
if (!$SmartBlogPost->save()) {
$this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
} else {
Hook::exec('actionsbnewpost', array('SmartBlogPost' => $SmartBlogPost));
$this->updateTags($languages, $SmartBlogPost);
$this->processImage($_FILES, $SmartBlogPost->id);
Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogPost'));
}
} elseif ($id_smart_blog_post = Tools::getValue('id_smart_blog_post')) {
$SmartBlogPost = new $SmartBlogPost($id_smart_blog_post);
$languages = Language::getLanguages(false);
foreach ($languages as $language) {
$title = Tools::link_rewrite(Tools::getValue('meta_title_' . $language['id_lang']));
$SmartBlogPost->meta_title[$language['id_lang']] = $title;
$SmartBlogPost->meta_keyword[$language['id_lang']] = Tools::getValue('meta_keyword_' . $language['id_lang']);
$SmartBlogPost->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
$SmartBlogPost->short_description[$language['id_lang']] = Tools::getValue('short_description_' . $language['id_lang']);
$SmartBlogPost->content[$language['id_lang']] = Tools::getValue('content_' . $language['id_lang']);
$SmartBlogPost->link_rewrite[$language['id_lang']] = Tools::link_rewrite(Tools::getValue('link_rewrite_' . $language['id_lang']));
}
$SmartBlogPost->is_featured = Tools::getValue('is_featured');
$SmartBlogPost->id_parent = Tools::getValue('id_parent');
$SmartBlogPost->active = Tools::getValue('active');
$SmartBlogPost->id_category = Tools::getValue('id_category');
$SmartBlogPost->comment_status = Tools::getValue('comment_status');
$SmartBlogPost->id_author = $this->context->employee->id;
$SmartBlogPost->modified = Date('y-m-d H:i:s');
if (!$SmartBlogPost->update()) {
$this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
} else {
Hook::exec('actionsbupdatepost', array('SmartBlogPost' => $SmartBlogPost));
}
$this->updateTags($languages, $SmartBlogPost);
$this->processImage($_FILES, $SmartBlogPost->id_smart_blog_post);
Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogPost'));
}
} elseif (Tools::isSubmit('statussmart_blog_post') && Tools::getValue($this->identifier)) {
if ($this->tabAccess['edit'] === '1') {
if (Validate::isLoadedObject($object = $this->loadObject())) {
if ($object->toggleStatus()) {
Hook::exec('actionsbtogglepost', array('SmartBlogPost' => $this->object));
$identifier = (int) $object->id_parent ? '&id_smart_blog_post=' . (int) $object->id_parent : '';
Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogPost'));
} else {
$this->errors[] = Tools::displayError('An error occurred while updating the status.');
}
} else {
$this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
}
//.........这里部分代码省略.........
示例10: processAddAttachments
/**
* Method processAddAttachments() : Change name of file which are uploaded for this product
* Rules:
* - For the first upload the filename has been : name-of-product.extention
* - For the second upload : name-of-product-1.extention
* - ...
*
* @module now_seo_links
* @return void
*
* @see AdminProductsControllerCore::processAddAttachments()
*/
public function processAddAttachments()
{
$languages = Language::getLanguages(false);
$is_attachment_name_valid = false;
foreach ($languages as $language) {
$attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
if (Tools::strlen($attachment_name_lang) > 0) {
$is_attachment_name_valid = true;
}
if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) {
$this->errors[] = Tools::displayError('Invalid Name');
} elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) {
$this->errors[] = sprintf(Tools::displayError('The name is too long (%d chars max).'), 32);
}
if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) {
$this->errors[] = Tools::displayError('Invalid description');
}
}
if (!$is_attachment_name_valid) {
$this->errors[] = Tools::displayError('An attachment name is required.');
}
if (empty($this->errors)) {
if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) {
if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) {
$this->errors[] = sprintf($this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you\'re trying to upload is: %2$d kB.'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', ''));
} else {
do {
$uniqid = sha1(microtime());
} while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid));
if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) {
$this->errors[] = $this->l('File copy failed');
}
@unlink($_FILES['attachment_file']['tmp_name']);
}
} elseif ((int) $_FILES['attachment_file']['error'] === 1) {
$max_upload = (int) ini_get('upload_max_filesize');
$max_post = (int) ini_get('post_max_size');
$upload_mb = min($max_upload, $max_post);
$this->errors[] = sprintf($this->l('The file %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), '<b>' . $_FILES['attachment_file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>');
} else {
$this->errors[] = Tools::displayError('The file is missing.');
}
if (empty($this->errors) && isset($uniqid)) {
$attachment = new Attachment();
foreach ($languages as $language) {
if (Tools::getIsset('attachment_name_' . (int) $language['id_lang'])) {
$attachment->name[(int) $language['id_lang']] = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
}
if (Tools::getIsset('attachment_description_' . (int) $language['id_lang'])) {
$attachment->description[(int) $language['id_lang']] = Tools::getValue('attachment_description_' . (int) $language['id_lang']);
}
}
if (Tools::getIsset('name_' . (int) Configuration::get('PS_LANG_DEFAULT'))) {
$sFilename = $_FILES['attachment_file']['name'];
$sExtention = substr($sFilename, strrpos($sFilename, '.') + 1);
$attachment->file_name = Tools::link_rewrite(trim(Tools::getValue('name_' . (int) Configuration::get('PS_LANG_DEFAULT'))));
// On regarde si c'est le premier document joint au produit ou pas
$aAttachmentOfProduct = $attachment->getAttachments(Context::getContext()->language->id, (int) Tools::getValue('id_product'));
$iNb = count($aAttachmentOfProduct);
if ($iNb > 0) {
$attachment->file_name .= '-' . $iNb;
}
$attachment->file_name .= '.' . $sExtention;
}
$attachment->file = $uniqid;
$attachment->mime = $_FILES['attachment_file']['type'];
if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) {
$this->errors[] = Tools::displayError('Invalid file extension');
}
if (!Validate::isGenericName($attachment->file_name)) {
$this->errors[] = Tools::displayError('Invalid file name');
}
if (Tools::strlen($attachment->file_name) > 128) {
$this->errors[] = Tools::displayError('The file name is too long.');
}
if (empty($this->errors)) {
$res = $attachment->add();
if (!$res) {
$this->errors[] = Tools::displayError('This attachment was unable to be loaded into the database.');
} else {
$id_product = (int) Tools::getValue($this->identifier);
$res = $attachment->attachProduct($id_product);
if (!$res) {
$this->errors[] = Tools::displayError('We were unable to associate this attachment to a product.');
}
}
} else {
$this->errors[] = Tools::displayError('Invalid file');
//.........这里部分代码省略.........
示例11: makeMenu
private function makeMenu()
{
global $cookie, $page_name;
foreach ($this->getMenuItems() as $item) {
$id = (int) substr($item, 3, strlen($item));
switch (substr($item, 0, 3)) {
case 'CAT':
$this->getCategory($id, $cookie->id_lang);
break;
case 'PRD':
$selected = $page_name == 'product' && Tools::getValue('id_product') == $id ? ' class="sfHover"' : '';
$product = new Product($id, true, $cookie->id_lang);
if (!is_null($product->id)) {
$this->_menu .= '<li' . $selected . '><a href="' . $product->getLink() . '">' . $product->name . '</a></li>' . PHP_EOL;
}
break;
case 'CMS':
$selected = $page_name == 'cms' && Tools::getValue('id_cms') == $id ? ' class="sfHover"' : '';
$cms = CMS::getLinks($cookie->id_lang, array($id));
if (count($cms)) {
$this->_menu .= '<li' . $selected . '><a href="' . $cms[0]['link'] . '">' . $cms[0]['meta_title'] . '</a></li>' . PHP_EOL;
}
break;
case 'MAN':
$selected = $page_name == 'manufacturer' && Tools::getValue('id_manufacturer') == $id ? ' class="sfHover"' : '';
$manufacturer = new Manufacturer($id, $cookie->id_lang);
if (!is_null($manufacturer->id)) {
if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) {
$manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name, false);
} else {
$manufacturer->link_rewrite = 0;
}
$link = new Link();
$this->_menu .= '<li' . $selected . '><a href="' . $link->getManufacturerLink($id, $manufacturer->link_rewrite) . '">' . $manufacturer->name . '</a></li>' . PHP_EOL;
}
break;
case 'SUP':
$selected = $page_name == 'supplier' && Tools::getValue('id_supplier') == $id ? ' class="sfHover"' : '';
$supplier = new Supplier($id, $cookie->id_lang);
if (!is_null($supplier->id)) {
$link = new Link();
$this->_menu .= '<li' . $selected . '><a href="' . $link->getSupplierLink($id, $supplier->link_rewrite) . '">' . $supplier->name . '</a></li>' . PHP_EOL;
}
break;
case 'LNK':
$link = MenuTopLinks::get($id, $cookie->id_lang);
if (count($link)) {
$this->_menu .= '<li><a href="' . $link[0]['link'] . '"' . ($link[0]['new_window'] ? ' target="_blank"' : '') . '>' . $link[0]['label'] . '</a></li>' . PHP_EOL;
}
break;
}
}
}
示例12: getAnchor
/**
* Get the combination url anchor of the product
*
* @param integer $id_product_attribute
* @return string
*/
public function getAnchor($id_product_attribute)
{
$attributes = Product::getAttributesParams($this->id, $id_product_attribute);
$anchor = '#';
foreach ($attributes as &$a) {
foreach ($a as &$b) {
$b = str_replace('-', '_', Tools::link_rewrite($b));
}
$anchor .= '/' . $a['group'] . '-' . $a['name'];
}
return $anchor;
}
示例13: add_new_category
function add_new_category($category_name,$parent_id){
global $webService;
$xml = $webService -> get(array('url' => PS_SHOP_PATH . '/api/categories?schema=synopsis'));
$resources = $xml -> children() -> children();
unset($resources->level_depth);
unset($resources->nb_products_recursive);
$resources->id_parent = $parent_id;
$resources->active = 1;
$resources->name->language[0] = $category_name;
$resources->link_rewrite->language[0] = Tools::link_rewrite($category_name);
$resources->name->language[1] = $category_name;
$resources->link_rewrite->language[1] = Tools::link_rewrite($category_name);
try {
$opt = array('resource' => 'categories');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
$result1 = $xml->children()->children();
return $result1->{'id'};
}catch (PrestaShopWebserviceException $ex) {
echo "<b>Error al setear la cantidad ->Error : </b>".$ex->getMessage().'<br>';
}
}
示例14: AddProduct
private function AddProduct($ref, $weight, $price, $cats, $name, $description, $cat_name, $images, $colors_prod, $sizes_prod, $table_content)
{
$ref_id = $ref . "00";
$id_product = (int) Db::getInstance()->getValue('SELECT id_product FROM ' . _DB_PREFIX_ . 'product WHERE reference = ' . $ref_id);
$product = $id_product ? new Product((int) $id_product, true) : new Product();
$product->reference = $ref_id;
$product->available_for_order = 1;
$product->available_now = 1;
$product->show_price = 1;
$product->out_of_stock = 1;
$product->condition = "new";
$product->id_tax_rules_group = 6;
$price = $this->CalculatePrice($price, $weight);
$product->price = floatval($price);
$product->active = (int) "1";
$product->quantity = (int) "10";
$product->weight = floatval($weight);
$product->minimal_quantity = (int) "1";
$product->name[1] = utf8_encode($name);
$description_trans = $this->GetDescTrans($description, $table_content);
$product->description[1] = utf8_encode($description_trans);
$product->description[2] = utf8_encode($description_trans);
$product->description_short[1] = utf8_encode("");
$product->link_rewrite[1] = Tools::link_rewrite($name);
if (!isset($product->date_add) || empty($product->date_add)) {
$product->date_add = date('Y-m-d H:i:s');
}
$product->date_upd = date('Y-m-d H:i:s');
array_unshift($cats, "Home");
/*
foreach ($cats as $cat )
{
$this->AddCategory($cat,$cats);
}
*/
$cat_id = $this->GetCatId($cat_name);
$product->id_category_default = $cat_id;
$all_cat_id = $this->GetAllCatId($cats);
$product->category = $all_cat_id;
$product->save();
$id_product = $product->id;
$product->updateCategories($all_cat_id, true);
$this->DeleteProductAttr($id_product);
foreach ($colors_prod as $col) {
if (strlen($col) < 4 && strtolower($col) != "red") {
$size_trans = $this->GetSizeTrans($col);
if ($size_trans != "nije prevedeno") {
$this->AddSize($size_trans);
$this->ConnectProductSize($id_product, $size_trans);
}
} else {
$color_trans = $this->GetColorTrans($col);
$this->ConnectProductColor($id_product, $color_trans);
}
}
foreach ($sizes_prod as $siz) {
$size_trans = $this->GetSizeTrans($siz);
if ($size_trans != "nije prevedeno") {
$this->AddSize($size_trans);
$this->ConnectProductSize($id_product, $size_trans);
}
$this->UpdateStock($id_product);
}
$image = new Image();
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = 1;
// or false;
foreach ($images as $url) {
$this->AddImage($product, $url);
}
return 'Proizvod <b>' . $product->name[1] . '</b> ' . ($id_product ? 'promjenjen' : 'dodan') . '<br />';
}
示例15: makeMenu
protected function makeMenu()
{
$menu_items = $this->getMenuItems();
$id_lang = (int) $this->context->language->id;
$id_shop = (int) Shop::getContextShopID();
foreach ($menu_items as $item) {
if (!$item) {
continue;
}
preg_match($this->pattern, $item, $value);
$id = (int) substr($item, strlen($value[1]), strlen($item));
switch (substr($item, 0, strlen($value[1]))) {
case 'CAT':
$this->_menu .= $this->generateCategoriesMenu(Category::getNestedCategories($id, $id_lang, false, $this->user_groups));
break;
case 'PRD':
$selected = $this->page_name == 'product' && Tools::getValue('id_product') == $id ? ' class="sfHover"' : '';
$product = new Product((int) $id, true, (int) $id_lang);
if (!is_null($product->id)) {
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($product->getLink()) . '" title="' . $product->name . '">' . $product->name . '</a></li>' . PHP_EOL;
}
break;
case 'CMS':
$selected = $this->page_name == 'cms' && Tools::getValue('id_cms') == $id ? ' class="sfHover"' : '';
$cms = CMS::getLinks((int) $id_lang, array($id));
if (count($cms)) {
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($cms[0]['link']) . '" title="' . Tools::safeOutput($cms[0]['meta_title']) . '">' . Tools::safeOutput($cms[0]['meta_title']) . '</a></li>' . PHP_EOL;
}
break;
case 'CMS_CAT':
$category = new CMSCategory((int) $id, (int) $id_lang);
if (count($category)) {
$this->_menu .= '<li><a href="' . Tools::HtmlEntitiesUTF8($category->getLink()) . '" title="' . $category->name . '">' . $category->name . '</a>';
$this->getCMSMenuItems($category->id);
$this->_menu .= '</li>' . PHP_EOL;
}
break;
// Case to handle the option to show all Manufacturers
// Case to handle the option to show all Manufacturers
case 'ALLMAN':
$link = new Link();
$this->_menu .= '<li><a href="' . $link->getPageLink('manufacturer') . '" title="' . $this->l('All manufacturers') . '">' . $this->l('All manufacturers') . '</a><ul>' . PHP_EOL;
$manufacturers = Manufacturer::getManufacturers();
foreach ($manufacturers as $key => $manufacturer) {
$this->_menu .= '<li><a href="' . $link->getManufacturerLink((int) $manufacturer['id_manufacturer'], $manufacturer['link_rewrite']) . '" title="' . Tools::safeOutput($manufacturer['name']) . '">' . Tools::safeOutput($manufacturer['name']) . '</a></li>' . PHP_EOL;
}
$this->_menu .= '</ul>';
break;
case 'MAN':
$selected = $this->page_name == 'manufacturer' && Tools::getValue('id_manufacturer') == $id ? ' class="sfHover"' : '';
$manufacturer = new Manufacturer((int) $id, (int) $id_lang);
if (!is_null($manufacturer->id)) {
if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) {
$manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name);
} else {
$manufacturer->link_rewrite = 0;
}
$link = new Link();
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($link->getManufacturerLink((int) $id, $manufacturer->link_rewrite)) . '" title="' . Tools::safeOutput($manufacturer->name) . '">' . Tools::safeOutput($manufacturer->name) . '</a></li>' . PHP_EOL;
}
break;
// Case to handle the option to show all Suppliers
// Case to handle the option to show all Suppliers
case 'ALLSUP':
$link = new Link();
$this->_menu .= '<li><a href="' . $link->getPageLink('supplier') . '" title="' . $this->l('All suppliers') . '">' . $this->l('All suppliers') . '</a><ul>' . PHP_EOL;
$suppliers = Supplier::getSuppliers();
foreach ($suppliers as $key => $supplier) {
$this->_menu .= '<li><a href="' . $link->getSupplierLink((int) $supplier['id_supplier'], $supplier['link_rewrite']) . '" title="' . Tools::safeOutput($supplier['name']) . '">' . Tools::safeOutput($supplier['name']) . '</a></li>' . PHP_EOL;
}
$this->_menu .= '</ul>';
break;
case 'SUP':
$selected = $this->page_name == 'supplier' && Tools::getValue('id_supplier') == $id ? ' class="sfHover"' : '';
$supplier = new Supplier((int) $id, (int) $id_lang);
if (!is_null($supplier->id)) {
$link = new Link();
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($link->getSupplierLink((int) $id, $supplier->link_rewrite)) . '" title="' . $supplier->name . '">' . $supplier->name . '</a></li>' . PHP_EOL;
}
break;
case 'SHOP':
$selected = $this->page_name == 'index' && $this->context->shop->id == $id ? ' class="sfHover"' : '';
$shop = new Shop((int) $id);
if (Validate::isLoadedObject($shop)) {
$link = new Link();
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($shop->getBaseURL()) . '" title="' . $shop->name . '">' . $shop->name . '</a></li>' . PHP_EOL;
}
break;
case 'LNK':
$link = MenuTopLinks::get((int) $id, (int) $id_lang, (int) $id_shop);
if (count($link)) {
if (!isset($link[0]['label']) || $link[0]['label'] == '') {
$default_language = Configuration::get('PS_LANG_DEFAULT');
$link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int) Shop::getContextShopID());
}
$this->_menu .= '<li><a href="' . Tools::HtmlEntitiesUTF8($link[0]['link']) . '"' . ($link[0]['new_window'] ? ' onclick="return !window.open(this.href);"' : '') . ' title="' . Tools::safeOutput($link[0]['label']) . '">' . Tools::safeOutput($link[0]['label']) . '</a></li>' . PHP_EOL;
}
break;
}
}
//.........这里部分代码省略.........