Using standard SEF in Joomla 1.5 I have links like: mysite.com/news/36-good-news-tooday.
I need to remove article ID from url and get something like this: mysite.com/news/good-news-today.
Note: It means I don't want use any plugins (like HP Router etc.)
I want edit Joomla own SEF.
UPD: Finally I found desicion. Here is full listing of router.php, wich you can find in components/com_content
<?php
/**
* #version $Id: router.php 14401 2010-01-26 14:10:00Z louis $
* #package Joomla
* #copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* #license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
function ContentBuildRoute(&$query)
{
$segments = array();
$menu = &JSite::getMenu();
if (empty($query['Itemid'])) {
$menuItem = &$menu->getActive();
} else {
$menuItem = &$menu->getItem($query['Itemid']);
}
$mView = (empty($menuItem->query['view']))? null : $menuItem->query['view'];
$mCatid = (empty($menuItem->query['catid']))? null : $menuItem->query['catid'];
$mId = (empty($menuItem->query['id']))? null : $menuItem->query['id'];
if(isset($query['task'])) {
return $segments;
}
if(isset($query['view']))
{
$view = $query['view'];
if(empty($query['Itemid'])) {
$segments[] = $query['view'];
}
unset($query['view']);
};
if (($mView == 'article') and (isset($query['id'])) and ($mId == intval($query['id']))) {
unset($query['view']);
unset($query['catid']);
unset($query['id']);
}
if (isset($view) and ($view == 'section' && !empty($query['Itemid']))) {
if (($mView != 'section') or ($mView == 'section' and $mId != intval($query['id']))) {
$segments[] = 'section';
unset($query['Itemid']);
}
}
if (isset($view) and $view == 'category') {
if ($mId != intval($query['id']) || $mView != $view) {
$temp = explode(':',$query['id']);
if(count($temp) > 1)
{
$query['id'] = $temp[1];
}
$segments[] = $query['id'];
}
unset($query['id']);
}
if (isset($query['catid'])) {
if ((($view == 'article') and ($mView != 'category') and ($mView != 'article') and ($mCatid != intval($query['catid'])))) {
$temp = explode(':',$query['catid']);
if(count($temp) > 1)
{
$query['catid'] = $temp[1];
}
$segments[] = $query['catid'];
}
unset($query['catid']);
};
if(isset($query['id'])) {
if (empty($query['Itemid'])) {
$temp = explode(':',$query['id']);
if(count($temp) > 1)
{
$query['id'] = $temp[1];
}
$segments[] = $query['id'];
} else {
if (isset($menuItem->query['id'])) {
if($query['id'] != $mId) {
$temp = explode(':',$query['id']);
if(count($temp) > 1)
{
$query['id'] = $temp[1];
}
$segments[] = $query['id'];
}
} else {
$temp = explode(':',$query['id']);
if(count($temp) > 1)
{
$query['id'] = $temp[1];
}
$segments[] = $query['id'];
}
}
unset($query['id']);
};
if(isset($query['year'])) {
if(!empty($query['Itemid'])) {
$segments[] = $query['year'];
unset($query['year']);
}
};
if(isset($query['month'])) {
if(!empty($query['Itemid'])) {
$segments[] = $query['month'];
unset($query['month']);
}
};
if(isset($query['layout']))
{
if(!empty($query['Itemid']) && isset($menuItem->query['layout'])) {
if ($query['layout'] == $menuItem->query['layout']) {
unset($query['layout']);
}
} else {
if($query['layout'] == 'default') {
unset($query['layout']);
}
}
};
return $segments;
}
function ContentParseRoute($segments)
{
$vars = array();
$menu =& JSite::getMenu();
$item =& $menu->getActive();
$db =& JFactory::getDBO();
$count = count($segments);
if(!isset($item))
{
$vars['view'] = $segments[0];
$vars['id'] = $segments[$count - 1];
if($vars['view'] == 'article')
{
$query = 'SELECT id FROM #__content WHERE alias = '.$db->Quote($vars['id']);
} elseif($vars['view'] == 'category') {
$query = 'SELECT id FROM #__categories WHERE section > 0 && alias = '.$db->Quote($vars['id']);
}
$db->setQuery($query);
$vars['id'] = $db->loadResult();
return $vars;
}
switch($item->query['view'])
{
case 'section' :
{
if($count == 1) {
$vars['view'] = 'category';
if(isset($item->query['layout']) && $item->query['layout'] == 'blog') {
$vars['layout'] = 'blog';
}
}
if($count == 2) {
$vars['view'] = 'article';
$vars['catid'] = $segments[$count-2];
}
$vars['id'] = $segments[$count-1];
} break;
case 'category' :
{
$vars['id'] = $segments[$count-1];
$vars['view'] = 'article';
} break;
case 'frontpage' :
{
$vars['id'] = $segments[$count-1];
$vars['view'] = 'article';
} break;
case 'article' :
{
$vars['id'] = $segments[$count-1];
$vars['view'] = 'article';
} break;
case 'archive' :
{
if($count != 1)
{
$vars['year'] = $count >= 2 ? $segments[$count-2] : null;
$vars['month'] = $segments[$count-1];
$vars['view'] = 'archive';
} else {
$vars['id'] = $segments[$count-1];
$vars['view'] = 'article';
}
}
}
$alias = explode(':', $vars['id']);
if((int) $alias[0] > 0)
{
$vars['id'] = $alias[0];
} else {
if(count($alias) > 1)
{
$vars['id'] = $alias[0].'-'.$alias[1];
}
if($vars['view'] == 'article')
{
$query = 'SELECT id FROM #__content WHERE alias = '.$db->Quote($vars['id']);
} elseif($vars['view'] == 'category') {
$query = 'SELECT id FROM #__categories WHERE section > 0 && alias = '.$db->Quote($vars['id']);
}
$db->setQuery($query);
$vars['id'] = $db->loadResult();
}
return $vars;
}
I'm not an author! Router code was modified by Marvin Ryan.
This code works perfect in most of cases!
But I have some problems with JoomFish language toggle.
It have links like www.mysite.com/news/22
So I get only article ID, not article alias. This problem is still actual!
Create menu items for every article.
Related
I am trying to read excel file and store that data in database. This excel file is kind of template. one would be default template and this template could be changed in future. Currently i am reading that file with many if conditions .I personally think that it isn't best way to read excel file so looking for better way.
this procedure is divided into two functions
public function importManifestFile(Request $request)
{
$path = $request->file('manifest_file')->getRealPath();
$spreadsheet = IOFactory::load($path);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
foreach ($sheetData as $rows => $ManifestConsignments) {
if ($rows >= 9 && $rows <= 37) {
$this->manifestConsignment($ManifestConsignments);
}
}
}
//import file manifest consignment function
public function manifestConsignment($ManifestConsignments)
{
$consignment = new Consignment;
foreach ($ManifestConsignments as $key => $ManifestConsignment) {
if ($key == 'A') {
}
if ($key == 'B') {
$consignment->delivery_date = $ManifestConsignment;
}
if ($key == 'C') {
$addressId = $ManifestConsignment;
}
if ($key == 'D') {
$companyName = $ManifestConsignment;
}
if ($key == 'E') {
$streetAddress = $ManifestConsignment;
}
if ($key == 'F') {
$suburb = $ManifestConsignment;
}
if ($key == 'G') {
$state = $ManifestConsignment;
}
if ($key == 'H') {
$postCode = $ManifestConsignment;
}
if (isset($postCode)) {
if (Address::where('company_name', $companyName)->where('street_address', $streetAddress)->where('suburb', $suburb)->where('state', $state)->where('postcode', $postCode)->exists()) {
$deliveryAddress = Address::where('company_name', $companyName)->where('street_address', $streetAddress)->where('suburb', $suburb)->where('state', $state)->where('postcode', $postCode)->first();
$deliveryAddressId = $deliveryAddress->id;
$consignment->delivery_address = $deliveryAddressId;
unset($postCode);
} else {
$address = new Address;
$address->company_name = $companyName;
$address->street_address = $streetAddress;
$address->suburb = $suburb;
$address->postcode = $postCode;
$address->state = $state;
$address->save();
$consignment->delivery_address = $address->id;
unset($postCode);
}
if ($key == 'I') {
$consignment->carton = $ManifestConsignment;
}
if ($key == 'J') {
$consignment->pallet = $ManifestConsignment;
}
if ($key == 'K') {
$consignment->weight = $ManifestConsignment;
}
if ($key == 'L') {
$consignment->invoice_value = $ManifestConsignment;
}
if ($key == 'M') {
if (!empty($ManifestConsignment)) {
$consignment->cash_on_delivery = $ManifestConsignment;
}
}
if ($key == 'N') {
$consignment->product_type_id = 1;
}
if ($key == 'O') {
$consignment->comment = $ManifestConsignment;
}
$consignment->customer_id =1;
$consignment->status = 'In Warehouse';
$consignment->product_type_id = 1;
$consignment->save();
}
}
}
$key
in code is column name of excel file . i am checking what is column name and storing data according to that.
can anyone help to me.
I have a module for show banners (and stickers) on product. Banner function show a banner only on product page of specific product, and stickers on page of specific product, and product list miniature.
(you can see screenshot) original page is: http://miofantasy.it/shampoo/2192-antica-erboristeria-shampoo-girasole-250-ml.html
screenshot
I want show the BANNER on product list miniature, beyond that product page, like in next screeshot modified (how already stichers does)
screenshot modified
original page is: http://miofantasy.it/
I'm don't know about code edit, and i don't know how to do it.
Anyone can said to me what i must modify.
Inside a file php of module, I have found this code, that i think manage the banner on product page:
public function hookDisplayProductButtons()
{
//Its an alternative, use only if productfooter hook is not available.
// get rid of 1 > 2 condition to activate
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') && 1 > 2) {
return $this-> hookDisplayFooterProduct();
}
}
public function hookDisplayFooterProduct()
{
$type = (int)Configuration::get('sticker_type_val');
$type = empty($type) ? 1 : $type;
if ($type > 0) {
$object = new Stickers();
$rules = new Rules();
$id = Tools::getValue('id_product');
$product = new Product((int)$id, true, $this->context->language->id);
$category_data = $product->getCategories();
$stickers_pro = $object->getProductStickers($id);
**$stickers_banner = $object->getProductBanner($id);**
$_price = Tools::ps_round($product->price);
//For Stickers Rules if any matches - Tags
$tags_exist = Tag::getProductTags((int)$id);
$new_stickers_colllection = $rules->keyNewExists();
$is_discounted = (int)$product->isDiscounted($product->id);
if (!empty($tags_exist)) {
$stickers_colllection = $rules->keyTagExists($tags_exist);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for reference match
if (!empty($product->reference)) {
$stickers_colllection = $rules->keyRefExists($product->reference);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for Price match
if ($_price > 0) {
$stickers_colllection = $rules->keyPriceExists($_price);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
$_stickers_colllection = $rules->keyPriceGreaterExists($_price);
if (!empty($_stickers_colllection)) {
foreach ($_stickers_colllection as $_stick) {
array_push($stickers_pro, $object->getSticker($_stick));
}
}
}
//Check for new Products match
if (!empty($new_stickers_colllection) && (int)$product->new > 0) {
foreach ($new_stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Check for Dsicounted Product rules
if ($is_discounted > 0) {
$stickers_colllection = $rules->keySaleExists();
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Finally check for category rule existance
$rule_category = $rules->getAllApplicable('category');
if (count($rule_category) > 0)
{
$category_applicable = array();
foreach ($category_data as $key)
{
$return = $rules->getIsCategoryStickerApplicable($key);
if (!empty($return))
{
$return = array_shift($return);
array_push($category_applicable, $return);
}
}
if (count($category_applicable) > 0)
{
foreach ($category_applicable as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Now check for brands rule existance
$rule_brands = $rules->getAllApplicable('brand');
if (count($rule_brands) > 0)
{
$stickers_colllection = $rules->keyBrandsExists($rule_brands, (int)$product->id_manufacturer);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Now check for supplier rule existance
$rule_supplier = $rules->getAllApplicable('supplier');
if (count($rule_supplier) > 0 && (int)$product->id_supplier > 0)
{
$stickers_colllection = $rules->keySupplierExists($rule_supplier, (int)$product->id_supplier);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
//echo '<pre>'; print_r($stickers_colllection); exit;
}
$base_image = __PS_BASE_URI__.'img/';
$position = Configuration::get('sticker_pos');
$size = Configuration::get('sticker_size');
$this->context->smarty->assign('base_image', $base_image);
$this->context->smarty->assign('size', $size);
$this->context->smarty->assign('position', $position);
$this->context->smarty->assign('id', $id);
$this->context->smarty->assign('stickers', $stickers_pro);
$this->context->smarty->assign('module_dir', _PS_MODULE_DIR_);
**$this->context->smarty->assign('stickers_banner', $stickers_banner);**
$force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
$this->context->smarty->assign(array(
'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
'base_dir_ssl' => _PS_BASE_URL_SSL_.__PS_BASE_URI__,
'force_ssl' => $force_ssl
)
);
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') == true) {
return $this->display(__FILE__, 'views/templates/hook/productfooter_17.tpl');
} else {
return $this->display(__FILE__, 'views/templates/hook/productfooter.tpl');
}
}
}
In bold character stickers_banner that i think manage the banner.
'views/templates/hook/productfooter_17.tpl' is the file where I find the file that i think manage banner layout, like this:
{if !empty($stickers_banner.title)}
{if empty($stickers)}<script type="text/javascript" src="{if $force_ssl ==
1}{$base_dir_ssl|escape:'htmlall':'UTF-8'}{else}
{$base_dir|escape:'htmlall':'UTF-8'}{/if}js/jquery/jquery-1.11.0.min.js">
</script>{/if}
{literal}
<script>
$('.product-price').after({/literal}'<div style="padding:10px 6px; margin-
bottom:10px; text-align:center;background:
{$stickers_banner.bg_color|escape:'htmlall':'UTF-8'};color:
{$stickers_banner.color|escape:'htmlall':'UTF-8'};border:1px solid
{$stickers_banner.border_color|escape:'htmlall':'UTF-8'};font-family:
{$stickers_banner.font|escape:'htmlall':'UTF-8'};font-size:
{$stickers_banner.font_size|escape:'htmlall':'UTF-8'}px;font-weight:
{$stickers_banner.font_weight|escape:'htmlall':'UTF-8'};">
{$stickers_banner.title|escape:'htmlall':'UTF-8'}</div>'{literal});
</script>
{/literal}
{/if}
Now the hook that i think to must modify for show banner in product list;
public function hookdisplayProductListFunctionalButtons($params)
{
$id = (int)$params['product']['id_product'];
$id = ($id <= 0) ? Tools::getValue('id_product') : $id;
$product = new Product((int)$id, true, $this->context->language->id);
$category_data = $product->getCategories();
$type = Configuration::get('sticker_type_val');
$type = empty($type) ? 1 : $type;
$stickers_pro = array();
$object = new Stickers();
$rules = new Rules();
$_price = Tools::ps_round($product->price);
//$page_name = Dispatcher::getInstance()->getController();
if ($type == 1) {
$new_stickers_colllection = $rules->keyNewExists();
$is_discounted = (int)$product->isDiscounted($product->id);
//For Stickers Rules if any matches
$tags_exist = Tag::getProductTags((int)$id);
if (!empty($tags_exist)) {
$stickers_colllection = $rules->keyTagExists($tags_exist);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for reference match
if (!empty($product->reference)) {
$stickers_colllection = $rules->keyRefExists($product->reference);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for Price match
if ($_price > 0) {
$stickers_colllection = $rules->keyPriceExists($_price);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
$_stickers_colllection = $rules->keyPriceGreaterExists($_price);
if (!empty($_stickers_colllection)) {
foreach ($_stickers_colllection as $_stick) {
array_push($stickers_pro, $object->getSticker($_stick));
}
}
}
//Check for new Products match
if (!empty($new_stickers_colllection) && (int)$product->new > 0) {
foreach ($new_stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Check for Discounted Product rules
if ($is_discounted > 0) {
$stickers_colllection = $rules->keySaleExists();
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Finally check for category rule existance
$rule_category = $rules->getAllApplicable('category');
if (count($rule_category) > 0)
{
$category_applicable = array();
foreach ($category_data as $key)
{
$return = $rules->getIsCategoryStickerApplicable($key);
if (!empty($return))
{
$return = array_shift($return);
array_push($category_applicable, $return);
}
}
if (count($category_applicable) > 0)
{
foreach ($category_applicable as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Now check for brands rule existance
$rule_brands = $rules->getAllApplicable('brand');
if (count($rule_brands) > 0)
{
$stickers_colllection = $rules->keyBrandsExists($rule_brands, (int)$product->id_manufacturer);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Now check for supplier rule existance
$rule_supplier = $rules->getAllApplicable('supplier');
if (count($rule_supplier) > 0 && (int)$product->id_supplier > 0)
{
$stickers_colllection = $rules->keySupplierExists($rule_supplier, (int)$product->id_supplier);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
//echo '<pre>'; print_r($stickers_colllection); exit;
}
}
$position = Configuration::get('sticker_pos');
$size = Configuration::get('sticker_size');
$base_image = __PS_BASE_URI__.'img/';
$this->context->smarty->assign('base_image', $base_image);
$this->context->smarty->assign('name', $params['product']['name']);
$this->context->smarty->assign('size', $size);
$this->context->smarty->assign('position', $position);
$this->context->smarty->assign('module_dir', _PS_MODULE_DIR_);
$this->context->smarty->assign('id', $id);
if ($type == 1) {
$stickercollection_ = $object->getProductStickers($params['product']['id_product']);
foreach ($stickercollection_ as $stick) {
array_push($stickers_pro, $stick);
}
}
$this->context->smarty->assign('stickers', $stickers_pro);
$force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
$this->context->smarty->assign(array(
'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
'base_dir_ssl' => _PS_BASE_URL_SSL_.__PS_BASE_URI__,
'force_ssl' => $force_ssl
)
);
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') == true) {
return $this->display(__FILE__, 'views/templates/hook/listing_17.tpl');
} else {
return $this->display(__FILE__, 'views/templates/hook/listing.tpl');
}
}
There is also hookdisplayStickers, i don't know if is impotant for this.
What can I modify for show the banner in product list.
Please anyone can help me?
Thanks
UPDATE:
I have add code
public function hookDisplayProductPriceBlock($params)
{
if ($params['type'] == 'before_price') {
// old_price or unit_price or weight
$id = (int)$params['product']['id_product'];
$_POST('id_product') = $id;
return $this->hookDisplayFooterProduct();
}
}
below hookdisplayProductListFunctionalButtons, and I have added code for register hook displayProductPriceBlock
public function install()
{
if (!$this->existsTab($this->tab_class)) {
if (!$this->addTab($this->tab_class, 0)) {
return false;
}
}
mkdir(_PS_IMG_DIR_.'stickers', 0777, true);
if (!parent::install()
|| !$this->installDb()
|| !$this->registerHook('displayCatalogListing')
|| !$this->registerHook('displayProductListFunctionalButtons')
|| !$this->registerHook('displayProductPriceBlock')
|| !$this->registerHook('displayAdminProductsExtra')
|| !$this->registerHook('actionProductUpdate')
|| !$this->registerHook('displayBackOfficeHeader')
|| !$this->registerHook('displayProductListReviews')
|| !$this->registerHook('displayProductButtons')
|| !$this->registerHook('displayFooterProduct')) {
return false;
}
return true;
}
But when I install module, I have error and prestashop not install module. I have used hookDisplayPriceBlock because I have found already writed hookDisplayProductListReviews :
public function hookDisplayProductListReviews($params)
{
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
return $this->hookdisplayProductListFunctionalButtons($params);
}
}
that i think it redirect prestashop 1.7 to hookdisplayProductListFunctionalButtons.
I was thinking, if hookDisplayProductListReviews redirect to hookdisplayProductListFunctionalButtons, is possible to edit hookdisplayProductListFunctionalButtons and add the code for show the banner, like in hookDisplayFooterProduct, where is written specific code for show the Banner?
How to do?
Thanks
You have to modify your banner module to do it.
Probably the problem will be solved by adding new hook (displayProductListFunctionalButtons or displayProductPriceBlock) to this module.
It requires the ability to cretae the module for Prestashop.
UPDATE :
Prestashop seems to have removed HookdisplayProductListFunctionalButtons from version 1.7
So you can use displayProductPriceBlock or displayProductListReviews :
public function HookDisplayProductListReviews($params)
{
$id = (int)$params['product']['id_product'];
$_POST('id_product') = $id;
return $this->hookDisplayFooterProduct();
}
If you want to use displayProductPriceBlock, you have to pay attention that it has several positions:
public function displayProductPriceBlock($params)
{
if($params['type'] == 'before_price') { // old_price or unit_price or weight
$id = (int)$params['product']['id_product'];
$_POST('id_product') = $id;
return $this->hookDisplayFooterProduct();
}
}
Tip: Do not forget that new hooks should be registered in the module installation method:
$this->registerHook('HookDisplayProductListReviews');
i have a problem in my multiple filters implementation. I have some checkboxes that pass to AJAX some params that can have multiple values.
In my controller i have written this to handle this params:
function getCategoria(Request $request) {
$path_info = Request::getPathInfo();
$path = substr($path_info, 1);
$links = explode('/', $path);
$categorie = \App\Models\Categorie::where('primaria',1)->get();
$categoria = \App\Models\Categorie::where('link_statico', $path)->first();
$categoriaz = \App\Models\Categorie::where('link_statico', $path)->first();
$id = ucfirst($links[0]);
$prodottip = \App\Models\Prdotticategorie::where('prodotti2categorie.id_categoria', $categoriaz->id)->join('prodotti', 'prodotti.id', '=', 'prodotti2categorie.id_prodotto')->query();
$brands = Input::get('brands');
$genere = Input::get('genere');
$stagione = Input::get('stagione');
$this->data['links'] = $links;
$this->data['categorie'] = $categorie;
$this->data['categoria'] = $categoria;
$this->data['categoriaz'] = $categoriaz;
$this->data['id'] = $id;
$this->data['pages'] = 'categorie.frontend';
if(count($brands) > 0 && count($genere) > 0 && count($stagione) > 0)
{
if(count($brands) > 0)
{
$brands_array = [];
if(is_array($brands) || is_object($brands))
{
foreach ($brands as $brand)
{
$brands_array[] = $brand;
}
$rst = $prodottip->whereIn('prodotti.id_produttore', $brands_array);
}
}
if(count($genere) > 0)
{
$genere_array = [];
if(is_array($genere) || is_object($genere))
{
foreach ($genere as $gen)
{
$genere_array[] = $gen;
}
$rst = $prodottip->whereIn('prodotti.genere', $genere_array);
}
}
if (count($stagione) > 0)
{
$stagione_array = [];
if(is_array($stagione) || is_object($stagione))
{
foreach ($stagione as $stag)
{
$stagione_array[] = $gen;
}
$rst = $prodottip->whereIn('prodotti.stagione', $stagione_array);
}
}
$prodottix = $rst->paginate(18);
} else {
$prodottix = $prodottip->paginate(18);
}
$this->data['prodottix'] = $prodottix;
if (Request::ajax()) {
$page = 'layouts.'.CNF_THEME.'.categorie_ajax';
$view = view($page, $this->data)->render();
return response()->json(['html'=>$view]);
}
$page = 'layouts.'.CNF_THEME.'.categorie';
return view($page, $this->data);
}
The problem is that AJAX reload correctly but the results remaining the same. I can bring it working only if i an elseif with different scenarios like this:
if(count($brands) > 0 && count($genere) > 0 && count($stagione) > 0)
//query with 3 where
elseif(count($brands) > 0 && count($genere) == 0 && count($stagione) == 0)
// query with 1 where
Hi have read something on DynamicScopes in Laravel, but i need more help thks
function getCategoria(Request $request)
{
$path_info = Request::getPathInfo();
$path = substr($path_info, 1);
$links = explode('/', $path);
$categorie = \App\Models\Categorie::where('primaria', 1)->get();
$categoria = \App\Models\Categorie::where('link_statico', $path)->first();
$categoriaz = \App\Models\Categorie::where('link_statico', $path)->first();
$id = ucfirst($links[0]);
$prodottip = \App\Models\Prdotticategorie::where('prodotti2categorie.id_categoria', $categoriaz->id)->join('prodotti', 'prodotti.id', '=', 'prodotti2categorie.id_prodotto')->query();
$brands = Input::get('brands');
$genere = Input::get('genere');
$stagione = Input::get('stagione');
$this->data['links'] = $links;
$this->data['categorie'] = $categorie;
$this->data['categoria'] = $categoria;
$this->data['categoriaz'] = $categoriaz;
$this->data['id'] = $id;
$this->data['pages'] = 'categorie.frontend';
$rst = null;
if (count($brands) > 0) {
$brands = is_object($brands) ? array($brands) : $brands;
$rst = $prodottip->whereIn('prodotti.id_produttore', $brands);
}
if (count($brands) > 0) {
$genere = is_object($genere) ? array($genere) : $genere;
$rst = $prodottip->whereIn('prodotti.genere', $genere);
}
if (count($stagione) > 0) {
$stagione = is_object($stagione) ? array($stagione) : $stagione;
$rst = $prodottip->whereIn('prodotti.stagione', $stagione);
}
if(null !== $rst) {
$prodottix = $rst->paginate(18);
} else {
$prodottix = $prodottip->paginate(18);
}
$this->data['prodottix'] = $prodottix;
if (Request::ajax()) {
$page = 'layouts.' . CNF_THEME . '.categorie_ajax';
$view = view($page, $this->data)->render();
return response()->json(['html' => $view]);
}
$page = 'layouts.' . CNF_THEME . '.categorie';
return view($page, $this->data);
}
Considering $brands,$genere,$stagione are array by
default. If it is object then then type casting to array and using in
the query.
Removed first if condition which is checking count
of all 3 arrays and then trying to build up a query.
Created new variable $rst which is having default value as null. In any condition is satisfied then it will assign the query object to $rst.
At last checking is $rst not equal to null and calling its paginate method.
Hope this will clears to you and solve your problem. If not,at least you will get an idea how you can re-factor your code :)
function getCategoria(Request $request) {
$path_info = Request::getPathInfo();
$path = substr($path_info, 1);
$links = explode('/', $path);
$categorie = \App\Models\Categorie::where('primaria',1)->get();
$categoria = \App\Models\Categorie::where('link_statico', $path)->first();
$categoriaz = \App\Models\Categorie::where('link_statico', $path)->first();
$id = ucfirst($links[0]);
$prodottip = \App\Models\Prdotticategorie::where('prodotti2categorie.id_categoria', $categoriaz->id)->join('prodotti', 'prodotti.id', '=', 'prodotti2categorie.id_prodotto')->query();
$brands = Input::get('brands');
$genere = Input::get('genere');
$stagione = Input::get('stagione');
$this->data['links'] = $links;
$this->data['categorie'] = $categorie;
$this->data['categoria'] = $categoria;
$this->data['categoriaz'] = $categoriaz;
$this->data['id'] = $id;
$this->data['pages'] = 'categorie.frontend';
if(count($brands) > 0 && count($genere) > 0 && count($stagione) > 0)
{
if(count($brands) > 0)
{
$brands_array = [];
if(is_array($brands) || is_object($brands))
{
foreach ($brands as $brand)
{
$brands_array[] = $brand;
}
$prodottip = $prodottip->whereIn('prodotti.id_produttore', $brands_array);
}
}
if(count($genere) > 0)
{
$genere_array = [];
if(is_array($genere) || is_object($genere))
{
foreach ($genere as $gen)
{
$genere_array[] = $gen;
}
$prodottip = $prodottip->whereIn('prodotti.genere', $genere_array);
}
}
if (count($stagione) > 0)
{
$stagione_array = [];
if(is_array($stagione) || is_object($stagione))
{
foreach ($stagione as $stag)
{
$stagione_array[] = $gen;
}
$prodottip = $prodottip->whereIn('prodotti.stagione', $stagione_array);
}
}
}
$prodottix = $prodottip->paginate(18);
$this->data['prodottix'] = $prodottix;
if (Request::ajax()) {
$page = 'layouts.'.CNF_THEME.'.categorie_ajax';
$view = view($page, $this->data)->render();
return response()->json(['html'=>$view]);
}
$page = 'layouts.'.CNF_THEME.'.categorie';
return view($page, $this->data);
}
I'm overriding the mod_mainmenu module in Joomla 1.5 and am unable to get the .active or #current CSS class or ID to show on the page. It's showing the following HTML for the menu:
<ul id="top-nav" class="flatList">
<li access="0" level="1" id="1">
<a href="#">
<span class="embed embed-top-nav">Home</span>
<p>news, highlights</p>
</a>
</li>
<li access="0" level="1" id="4">
<a href="/content/index.php?option=com_content&view=article&id=1&Itemid=4">
<span class="embed embed-top-nav">Watch UNC-TV</span>
<p>schedule, programs</p>
</a>
</li>
</ul>
I've read that the mod_mainmenu will automatically insert either active or current somewhere into this so you can tell which item is the currently active menu selection. But I'm not seeing either of those in the generated HTML. I'd like to apply some CSS to the active element, but there doesn't seem to be any way to do this. Any thoughts?
Thanks.
UPDATE: Here's the code of the mod_mainmenu I've created:
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
if ( ! defined('fancyMenuPatch') )
{
function fancyMenuPatch($result,$tag){
$menu = JSite::getMenu();
$active = $menu->getActive();
// Add to the start of the UL tag.
$begin_ul = "<ul id=\"top-nav\" class=\"flatList\">";
$begin_span = "<span class=\"embed embed-top-nav\">";
$home_p = "Home</span><p>news, highlights</p></a>";
$watch_p = "Watch UNC-TV</span><p>schedule, programs</p></a>";
$learn_p = "Learn</span><p>education, unc-tv kids</p></a>";
$support_p = "Support Us</span><p>pledge, volunteer, corporate</p></a>";
$contact_p = "Contact</span><p>feedback, connect, share</p></a>";
// do the replacements
$result = str_replace("<ul class=\"menu\">",$begin_ul, $result);
$result = str_replace("<span>", $begin_span, $result);
$result = str_replace("Home</span></a>",$home_p,$result);
$result = str_replace("Watch UNC-TV</span></a>",$watch_p,$result);
$result = str_replace("Learn</span></a>",$learn_p,$result);
$result = str_replace("Support Us</span></a>",$support_p,$result);
$result = str_replace("Contact</span></a>",$contact_p,$result);
return $result;
}
define('fancyMenuPatch', true);
}
if ( ! defined('modMainMenuXMLCallbackDefined') )
{
function modMainMenuXMLCallback(&$node, $args)
{
$user = &JFactory::getUser();
$menu = &JSite::getMenu();
$active = $menu->getActive();
$path = isset($active) ? array_reverse($active->tree) : null;
if (($args['end']) && ($node->attributes('level') >= $args['end']))
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
if ($node->name() == 'ul') {
foreach ($node->children() as $child)
{
if ($child->attributes('access') > $user->get('aid', 0)) {
$node->removeChild($child);
}
}
}
if (($node->name() == 'li') && isset($node->ul)) {
$node->addAttribute('class', 'parent');
}
if (isset($path) && (in_array($node->attributes('id'), $path) || in_array($node->attributes('rel'), $path)))
{
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' active');
} else {
$node->addAttribute('class', 'active');
}
}
else
{
if (isset($args['children']) && !$args['children'])
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
}
if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' item'.$id);
} else {
$node->addAttribute('class', 'item'.$id);
}
}
if (isset($path) && $node->attributes('id') == $path[0]) {
$node->addAttribute('id', 'current');
} else {
$node->removeAttribute('id');
}
$node->removeAttribute('rel');
$node->removeAttribute('level');
$node->removeAttribute('access');
}
define('modMainMenuXMLCallbackDefined', true);
}
ob_start();
modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback');
$menu_html = ob_get_contents();
ob_end_clean();
if($params->get('menutype')=="mainmenu"){
$tag = $params->get('tag_id');
}
//output the menu!
echo fancyMenuPatch($menu_html,$tag);
?>
Try this, here's code for mod_mainmenu (override):
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
if ( ! defined('fancyMenuPatch') )
{
function fancyMenuPatch($result,$tag){
$menu = JSite::getMenu();
$active = $menu->getActive();
// Add to the start of the UL tag.
$begin_ul = "<ul id=\"top-nav\" class=\"flatList\">";
$begin_span = "<span class=\"embed embed-top-nav\">";
$home_p = "Home</span><p>news, highlights</p></a>";
$watch_p = "Watch UNC-TV</span><p>schedule, programs</p></a>";
$learn_p = "Learn</span><p>education, unc-tv kids</p></a>";
$support_p = "Support Us</span><p>pledge, volunteer, corporate</p></a>";
$contact_p = "Contact</span><p>feedback, connect, share</p></a>";
// do the replacements
$result = str_replace("<ul class=\"menu\">",$begin_ul, $result);
$result = str_replace("<span>", $begin_span, $result);
$result = str_replace("Home</span></a>",$home_p,$result);
$result = str_replace("Watch UNC-TV</span></a>",$watch_p,$result);
$result = str_replace("Learn</span></a>",$learn_p,$result);
$result = str_replace("Support Us</span></a>",$support_p,$result);
$result = str_replace("Contact</span></a>",$contact_p,$result);
return $result;
}
define('fancyMenuPatch', true);
}
if ( ! defined('modMyMainMenuXMLCallbackDefined') )
{
function modMyMainMenuXMLCallback(&$node, $args)
{
$user = &JFactory::getUser();
$menu = &JSite::getMenu();
$active = $menu->getActive();
$path = isset($active) ? array_reverse($active->tree) : null; if (($args['end']) && ($node->attributes('level') >= $args['end']))
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
if ($node->name() == 'ul') {
foreach ($node->children() as $child)
{
if ($child->attributes('access') > $user->get('aid', 0)) {
$node->removeChild($child);
}
}
}
if (($node->name() == 'li') && isset($node->ul)) {
$node->addAttribute('class', 'parent');
}
if (isset($path) && in_array($node->attributes('id'), $path))
{
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' active');
} else {
$node->addAttribute('class', 'active');
}
}
else
{
if (isset($args['children']) && !$args['children'])
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
}
if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' item'.$id);
} else {
$node->addAttribute('class', 'item'.$id);
}
}
if (isset($path) && $node->attributes('id') == $path[0]) {
$node->addAttribute('id', 'current');
} else {
$node->removeAttribute('id');
}
$node->removeAttribute('level');
$node->removeAttribute('access');
}
define('modMyMainMenuXMLCallbackDefined', true);
}
ob_start();
modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback');
$menu_html = ob_get_contents();
ob_end_clean();
if($params->get('menutype')=="mainmenu"){
$tag = $params->get('tag_id');
}
//output the menu!
echo fancyMenuPatch($menu_html,$tag);
?>
Check your template folder, there is a template.css file, you can find there !
Hi
i have problem with the final_price,min_price,max_price in the catalog_product_index_price table its is wrongly inserting the values after function save() during import.
The file is app\code\core\Mage\Catalog\Model\Convert\Adapter\Product.php
The control goes to finish() function
public function finish()
{
Mage::dispatchEvent('catalog_product_import_after', array());
$entity = new Varien_Object();
Mage::getSingleton('index/indexer')->processEntityAction(
$entity, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
);
}
where is the insert statement to insert the value in the catalog_product_index_price table?
How this can be resolved?
My saveRow fucnction to populate database.My excel sheet contains the following additional row
Price Type:radio:1
Unit Price:absolute:2691|Case Price:absolute:12420
Unit Price:absolute:762|Case Price:absolute:7029
The save database function is
public function saveRow(array $importData)
{
$product = $this->getProductModel()
->reset();
if (empty($importData['store'])) {
if (!is_null($this->getBatchParams('store'))) {
$store = $this->getStoreById($this->getBatchParams('store'));
} else {
$message = Mage::helper('catalog')->__('Skipping import row, required field "%s" is not defined.', 'store');
Mage::throwException($message);
}
}
else {
$store = $this->getStoreByCode($importData['store']);
}
if ($store === false) {
$message = Mage::helper('catalog')->__('Skipping import row, store "%s" field does not exist.', $importData['store']);
Mage::throwException($message);
}
if (empty($importData['sku'])) {
$message = Mage::helper('catalog')->__('Skipping import row, required field "%s" is not defined.', 'sku');
Mage::throwException($message);
}
$product->setStoreId($store->getId());
$productId = $product->getIdBySku($importData['sku']);
if ($productId) {
$product->load($productId);
}
else {
$productTypes = $this->getProductTypes();
$productAttributeSets = $this->getProductAttributeSets();
/**
* Check product define type
*/
if (empty($importData['type']) || !isset($productTypes[strtolower($importData['type'])])) {
$value = isset($importData['type']) ? $importData['type'] : '';
$message = Mage::helper('catalog')->__('Skip import row, is not valid value "%s" for field "%s"', $value, 'type');
Mage::throwException($message);
}
$product->setTypeId($productTypes[strtolower($importData['type'])]);
/**
* Check product define attribute set
*/
if (empty($importData['attribute_set']) || !isset($productAttributeSets[$importData['attribute_set']])) {
$value = isset($importData['attribute_set']) ? $importData['attribute_set'] : '';
$message = Mage::helper('catalog')->__('Skip import row, the value "%s" is invalid for field "%s"', $value, 'attribute_set');
Mage::throwException($message);
}
$product->setAttributeSetId($productAttributeSets[$importData['attribute_set']]);
foreach ($this->_requiredFields as $field) {
$attribute = $this->getAttribute($field);
if (!isset($importData[$field]) && $attribute && $attribute->getIsRequired()) {
$message = Mage::helper('catalog')->__('Skipping import row, required field "%s" for new products is not defined.', $field);
Mage::throwException($message);
}
}
}
$this->setProductTypeInstance($product);
if (isset($importData['category_ids'])) {
$product->setCategoryIds($importData['category_ids']);
}
foreach ($this->_ignoreFields as $field) {
if (isset($importData[$field])) {
unset($importData[$field]);
}
}
if ($store->getId() != 0) {
$websiteIds = $product->getWebsiteIds();
if (!is_array($websiteIds)) {
$websiteIds = array();
}
if (!in_array($store->getWebsiteId(), $websiteIds)) {
$websiteIds[] = $store->getWebsiteId();
}
$product->setWebsiteIds($websiteIds);
}
if (isset($importData['websites'])) {
$websiteIds = $product->getWebsiteIds();
if (!is_array($websiteIds)) {
$websiteIds = array();
}
$websiteCodes = explode(',', $importData['websites']);
foreach ($websiteCodes as $websiteCode) {
try {
$website = Mage::app()->getWebsite(trim($websiteCode));
if (!in_array($website->getId(), $websiteIds)) {
$websiteIds[] = $website->getId();
}
}
catch (Exception $e) {}
}
$product->setWebsiteIds($websiteIds);
unset($websiteIds);
}
$custom_options = array();
foreach ($importData as $field => $value) {
if (in_array($field, $this->_inventoryFields)) {
continue;
}
if (in_array($field, $this->_imageFields)) {
continue;
}
$attribute = $this->getAttribute($field);
if (!$attribute) {
/* CUSTOM OPTION CODE */
if(strpos($field,':')!==FALSE && strlen($value)) {
$values=explode('|',$value);
if(count($values)>0) {
#list($title,$type,$is_required,$sort_order) = explode(':',$field);
$title = ucfirst(str_replace('_',' ',$title));
$custom_options[] = array(
'is_delete'=>0,
'title'=>$title,
'previous_group'=>'',
'previous_type'=>'',
'type'=>$type,
'is_require'=>$is_required,
'sort_order'=>$sort_order,
'values'=>array()
);
foreach($values as $v) {
$parts = explode(':',$v);
$title = $parts[0];
if(count($parts)>1) {
$price_type = $parts[1];
} else {
$price_type = 'fixed';
}
if(count($parts)>2) {
$price = $parts[2];
} else {
$price =0;
}
if(count($parts)>3) {
$sku = $parts[3];
} else {
$sku='';
}
if(count($parts)>4) {
$sort_order = $parts[4];
} else {
$sort_order = 0;
}
switch($type) {
case 'file':
/* TODO */
break;
case 'field':
case 'area':
$custom_options[count($custom_options) - 1]['max_characters'] = $sort_order;
/* NO BREAK */
case 'date':
case 'date_time':
case 'time':
$custom_options[count($custom_options) - 1]['price_type'] = $price_type;
$custom_options[count($custom_options) - 1]['price'] = $price;
$custom_options[count($custom_options) - 1]['sku'] = $sku;
break;
case 'drop_down':
case 'radio':
case 'checkbox':
case 'multiple':
default:
$custom_options[count($custom_options) - 1]['values'][]=array(
'is_delete'=>0,
'title'=>$title,
'option_type_id'=>-1,
'price_type'=>$price_type,
'price'=>$price,
'sku'=>$sku,
'sort_order'=>$sort_order,
);
break;
}
}
}
}
/* END CUSTOM OPTION CODE */
continue;
}
$isArray = false;
$setValue = $value;
if ($attribute->getFrontendInput() == 'multiselect') {
$value = explode(self::MULTI_DELIMITER, $value);
$isArray = true;
$setValue = array();
}
if ($value && $attribute->getBackendType() == 'decimal') {
$setValue = $this->getNumber($value);
}
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
if ($isArray) {
foreach ($options as $item) {
if (in_array($item['label'], $value)) {
$setValue[] = $item['value'];
}
}
} else {
$setValue = false;
foreach ($options as $item) {
if ($item['label'] == $value) {
$setValue = $item['value'];
}
}
}
}
$product->setData($field, $setValue);
}
if (!$product->getVisibility()) {
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
}
$stockData = array();
$inventoryFields = isset($this->_inventoryFieldsProductTypes[$product->getTypeId()])
? $this->_inventoryFieldsProductTypes[$product->getTypeId()]
: array();
foreach ($inventoryFields as $field) {
if (isset($importData[$field])) {
if (in_array($field, $this->_toNumber)) {
$stockData[$field] = $this->getNumber($importData[$field]);
}
else {
$stockData[$field] = $importData[$field];
}
}
}
$product->setStockData($stockData);
$imageData = array();
foreach ($this->_imageFields as $field) {
if (!empty($importData[$field]) && $importData[$field] != 'no_selection') {
if (!isset($imageData[$importData[$field]])) {
$imageData[$importData[$field]] = array();
}
$imageData[$importData[$field]][] = $field;
}
}
foreach ($imageData as $file => $fields) {
try {
$product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . trim($file), $fields);
}
catch (Exception $e) {}
}
$product->setIsMassupdate(true);
$product->setExcludeUrlRewrite(true);
$product->save();
/* Remove existing custom options attached to the product */
foreach ($product->getOptions() as $o) {
$o->getValueInstance()->deleteValue($o->getId());
$o->deletePrices($o->getId());
$o->deleteTitles($o->getId());
$o->delete();
}
/* Add the custom options specified in the CSV import file */
if(count($custom_options)) {
foreach($custom_options as $option) {
try {
$opt = Mage::getModel('catalog/product_option');
$opt->setProduct($product);
$opt->addOption($option);
$opt->saveOptions();
}
catch (Exception $e) {}
}
}
return true;
}
This section of the code has been quite well tested, so it's unlikely (though conceivable) that this is a bug that you need to correct in the indexer. Can you provide more detail about the discrepancy that you are seeing?
There is a very good chance that you are seeing unexpected results because of some product being enabled/disabled, etc etc.