Select siblings of blockcategories (Prestashop, Smarty) - smarty

We have a blockcategories menu in Prestashop with about 400 categories total including all the subcategories, and this is creating too many links on each of our page, resulting in not-optimal onpage SEO.
I want to add rel="nofollow" and some Javascript to all links except the root and the selected category and it's children and siblings.
Example:
- Subcategory A (Root, dofollow)
- Subcategory A-1(Sibling of selected, dofollow)
- Subcategory A-2 (Selected, dofollow)
- Subcategory A-2-a (Child of selected, dofollow)
- Subcategory A-2-b (Child of selected, dofollow)
- Subcategory A-2-c (Child of selected, dofollow)
- Subcategory A-3 (Sibling of selected, dofollow)
- Subcategory B (Root, dofollow)
- Subcategory B-1 (Nofollow)
- Subcategory B-2 (Nofollow)
- Subcategory B-2-a (Nofollow)
- Subcategory B-2-b (Nofollow)
- Subcategory B-3 (Nofollow)
- Subcategory C (Root, dofollow)
- Subcategory D (Root, dofollow)
I have been successful with Selecting the Root, the Selected and the Children of the selected. However I've been unsuccessful with selecting the Siblings of the selected (That share the same Parent).
How do I Select the Siblings of the Selected Category within the Blockcategories .tpl files?

PrestaShop is using a nested set model to store its categories:
http://www.fliquidstudios.com/2008/12/23/nested-set-in-mysql/
http://en.wikipedia.org/wiki/Nested_set_model
This allows you to easily select a part of the tree (parents, children, siblings, etc.).
Each "Category" object has a nleft and nright member that will help you to perform these selections.
Another easier way is to use the level_depth member, all siblings will have an identical level_depth value.
You can modify the blockcategories.php file to add level_depth in the SELECT statement of hookLeftColumn(). Then in the category-tree-branch.tpl file, simple add a test:
{if $node.level_depth == ....}rel="nofollow"{/if}
Be careful, Google might not like the fact that one some pages a category is nofollow and dofollow on other pages.

i've had very similar problem - i needed to change style of all siblings of the selected category so the solution is the same
you need to modify category-tree-branch.tpl
<li {if isset($last) && $last == 'true'}class="last"{/if}>
{assign var="RET" value=""}
{if $node.children|#count > 0}
{foreach from=$node.children item=child name=categoryTreeBranch}
{if $smarty.foreach.categoryTreeBranch.last}
{include file="$branche_tpl_path" node=$child last='true' assign='childItems'}
{else}
{include file="$branche_tpl_path" node=$child last='false' assign='childItems'}
{/if}
{assign var="RET" value="{$RET}{$childItems}"}
{/foreach}
{/if}
<a href="{$node.link|escape:'htmlall':'UTF-8'}" {if $RET|strpos:'selected'} class="parentselect"{/if}{if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if}
title="{$node.desc|strip_tags|trim|escape:'htmlall':'UTF-8'}">{$node.name|escape:'htmlall':'UTF-8'}</a>
{if $RET}<ul>{$RET}</ul>{/if}
</li>
all you need is to put whatever you need between {if $RET|strpos:'selected'} and {\if} for active branch ...or change the condition for non-selected branch {if $RET|strpos:'selected'==false}

I solved this by modifying blockcategories.php, blockcategories.tpl and category-tree-branch.tpl.
First in blockcategories.php I edited rows 148 and 246.
Row 148 is the getTree() where the module assign the return array called $node in the .tpl files. Here I add the following line to the array (I assign parent the id_parent value:
'parent' => $resultIds[$id_category]['id_parent']
At row 246 I add "currentCategoryParent" to the smarty->assign array.
$this->smarty->assign(array('currentCategory' => $category, 'currentCategoryId' => $category->id, 'currentCategoryParent' => $category->id_parent));
I can then access these variables from the .tpl files using $currentCategoryParent and $node.parent.

Related

How i can show many2one field all records on a form view instead drop down list in odoo 10?

How I can show many2one field all records on a form view instead drop down list in odoo 10.
For example, I have a Product category and Products.
When I select Product category from drop down list then all products belongs to that category shows on form view instead of a drop down list.
Here I assume you have category id like,
category_id = fields.Many2one('product.category', "Product Category")
Add Many2many of product.product field to your model for product records.
product_ids = fields.Many2many('product.product', "Products")
Now you need to define onchange on category_id field like.
#api.onchange('category_id')
def onchange_product_category(self):
if self.category_id:
self.product_ids = [(5,)] # unlink all existing records of product
product_recs = self.env['product.product'].search([('categ_id', '=', self.category_id.id)])
self.product_ids = [(4, x) for x in product_recs] # link the product records of selected category
If you do not want to display your product records in list view you can use widget many2many_tags in the form view like,
<field name="product_ids" widget="many2many_tags"/>
It will work for you.

Magento set "Show All" products by specific category (or in .phtml) rather than globally

I'm aware of the setting in the admin panel for the default number of products to show on the category list pages. This appears to be a global setting for the whole store. I'm looking for a way to set this on a per category basis (e.g. have most categories default to 25 products per page, but one specific category default to showing all products on the first page). Ideally this would be done in admin or in a .phtml file if possible. How can I set the default products per page for a specific category?
Take a look in
design/package/theme/catalog/product/list/toolbar.phtml
The items per page select drop down is generated by a for loop around:
$this->getAvailableLimit()
The block for the toolbar has the following method on it:
public function getLimitUrl($limit)
{
return $this->getPagerUrl(array(
$this->getLimitVarName() => $limit,
$this->getPageVarName() => null
));
}
The trick is to do one of the two following:
1) leverage magento to build the proper url when it is injected in any link directing to the category you want to be in view all mode.
2) on the /catalog/product/list/toolbar.phtml block check the current category, if the current category is the desired category execute the following code:
if( strtoupper($this->getLimitVarName()) != "ALL" )
{
$viewAllUrl = $this->getLimitUrl('All');
$this->_redirectUrl( $viewAllUrl );
}
At Admin Panel
Go to -> CMS -> Pages -> Home Page
Click on "Content" tab on LEFT
Click on "Show/Hide Editor" Button at RIGHT
Copy - Paste This Code there :
{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}
Give Category ID of your desired Category
To check Category_id of any category Go to : Catalog Menu -> Manage Catagories
Click on category, at right side's TITLE somewhat like will be displayed :
"CATEGORY_NAME ( ID : 5 )"
Regards.

Magento: show products of all subcategories when clicking a category, no is_anchor

We have a category structure like this:
Root
-- Category 1
---- Category 1 - 1
------- Category 1 - 1 - 1
------- Category 1 - 1 - 2
---- Category 1 - 2
-- Category 2
---- Category 2 - 1
---- Category 2 - 2
Normally, when a user clicks the root category, it appears as empty. Also Category 1 and 2 are empty (by mistake, it could be, that 1 or 2 products are there).
I want, that when a category is clicked, the products of all subcategories (and subcategories' subcategories) are shown (+ the products which are in the category itself).
We cannot use is_anchor, as this behaviour is only for one of three storeviews and is_anchor is global.
My idea would be to rewrite Mage_Catalog_Block_Product_List, so it returns subcategories' products when requesting a category but isn't there a simpler approach by adding a filter or so to all category-collection-requests?
Answers to similar questions are incomplete or use is_anchor.
I solved the problem now on my own.
I created a module which rewrites Mage_Catalog_Model_Category::getProductCollection()
The steps are as follows:
When there are no child categories, return the standard parent::getProductCollection()
When there are child categories, get all children categories' ids and save them as an array.
Add the current categories' id to the array.
Fetch a collection of all these categories and filter them by is_active.
Iterate through the category-collection and load every single category.
Get the product collection of every category and iterate through it, saving all product ids to an array. Append to the array when the next category gets loaded.
Build a product collection and add a filter with ->addAttributeToFilter('entity_id', array('in' => array_unique($result)));
Return the collection. It holds all products of all subcategories and the current categories' products, as desired (and it has no duplicates in it).

Magento How to get The Parent Category of A Sub-Category from A Product

Root Category (id: 1)
- Apparel (id: 2)
-- Shirts (id:4)
-- Pants (id:5)
- Accessories (id: 3)
-- Handbags (id:6)
-- Jewelry (id:7)
On Magento we can get the category Ids of a product by using $productObj->getCategoryIds()
$productObj = Mage::getModel('catalog/product')->load($product_id);
$categoryIds = $productObj->getCategoryIds();
Which will return an array of category Ids of the product. I have a specific need to get the first level parent of category of a product. Takes for example the category tree above, if a product is categorized in Pants category, I want to get the first level category which is Apparel (in this case, the product only tagged under Pants category but not tagged in Apparel category).
Question: what method can I use to get the parent category of a sub category, or is it possible to get the first level category from a product?
You can use the catalog/category model and its method getParentCategory():
foreach ($categoryIds as $iCategoryId) {
$m = Mage::getModel('catalog/category')
->load($iCategoryId)
->getParentCategory();
var_dump($m->debug());
}

How can I add "Quantity" to a VirtueMart "Browse" page?

My VirtueMart shop.browse page has the typical columns of SKU, Name, Price, and "Update" (which contains the Add to Cart button). I would like to add a Quantity column between Price and Update so that a buyer can choose a quantity prior to pressing the "Add to Cart" button.
Though I don't know HOW to do this, I think I know WHERE to do it:
/public_html/components/com_virtuemart/themes/default/templates/browse/includes/browse_listtable.tpl.php
Lines 67-72 of that file tell the program how to build the table, but what I DON'T know how to do is modify the code source to tell it to include quantity as an element for the table. Here's the code:
// Loop through each row and build the table
foreach($data as $key => $value) {
$table->addRow( $data[$key], 'class="sectiontableentry'.$i.'"', 'td', true );
$i = $i == 1 ? 2 : 1;
}
Which include file is actually being called in this foreach loop, and what code would I add to reference quantity data?
You should not modify your core code. If you just need to put quantity box inside your browse template use variable $form_addtocart
It will give you quantity box and add to cart button.
All variables for browse page and for flypage template you can find here:
http://virtuemart.net/documentation/Developer_Manual/Modifying_the_Layout.html
If this is not what you are trying to get, please be more specific, or show your web page.

Resources