My e-commerce inventory mainly contains street signs which i added some custom code to display the dimensions (H x W x L) of my signs in single product
However I have a few jackets that don't require dimensions.
I cannot find what fields or an example of an IF statement that will only let me display certain fields for a specific category.
I assume that dimensions is set in product data.
$meta = get_postmeta($post_id);
if ($meta['_width'][0] && $meta['_length'][0] && $meta['_height'][0]) {
//show the dimensions
}
Related
is it possible to track the route that the user took to get to a page ?
say that i have a post that have 2 different taxonomies
taxonomy 1 = make
taxonomy 2 = color
i want to create a different layout for each route
this is my current hierarchy:
Mercedes -> blue -> car - the user gets template 1 (single-car.php)
blue -> Mercedes -> car - the user gets template 1 (single-car.php)
this is what i want
Mercedes -> blue -> car - the user will get template 1 (single-car_by_make.php)
blue -> Mercedes -> car - the user will get template 2 (single-car_by_color.php)
is that possible without using extra query-strings ?
I am not writing actual code. But I just giving idea how to do it.
use the the following logic in the your single-car.php file
if(taxonomy == make )
get_template_part( 'single-car_by_make' );
if(taxonomy == color)
get_template_part( 'single-car_by_color' );
I hope It will help you.
I currently have a piece of code which will grab a product title, description, and price and for that it works great. However, I also need it to get the image URL which is where my dilemma is. I tried using a xpath inside the loop I have at the bottom and it lists out ALL the images that are equal to 220 on EVERY product which I dont want at all. So basically I get something like this....
product 1 Title here
product 1 Description here
product 1 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
product 2 Title here
product 2 Description here
product 2 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
Where as I obviously want product 1 to just have http://www.test.com/product1.jpg and product 2 to have http://www.test.com/product2.jpg etc, etc. The images are just in a div tag with no class or ID hence why I didnt just easily put them into a css selector. Im really new to ruby/nokogiri so any help would be great.
require 'nokogiri'
require 'open-uri'
url = "http://thewebsitehere"
data = Nokogiri::HTML(open(url))
products = data.css('.item')
products.each do |product|
puts product.at_css('.vproduct_list_title').text.strip
puts product.at_css('.vproduct_list_descr').text.strip
puts product.at_css('.price-value').text.strip
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
end
Try changing:
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
to:
puts product.xpath('.//img[#width = 220]/#src').map {|a| a.value }
The point of the '.' there is to say you want all images that are children of the current node (e.g. so you're not peeking at product 2's images).
File#basename will return only the filename:
File.basename('http://www.test.com/product4.jpg')
#=> "product4.jpg"
So you probably want something like this:
puts product.xpath('//img[#width = 220]/#src').map {|a| File.basename(a.value) }
I am working with Drupal Views, that filter our content based on geography, and shows news from a specific municipality.
Our taxonomy is hierarchical:
Regions
-- Municipalities from the region
--- Towns from the municipality
For example:
Region A (region)
-- Municipality X (municipality)
--- Town 1
--- Town 2
-- Municipality Y (municipality)
--- Town 3
--- Town 4
-- Municipality Z (municipality)
--- Town 5
--- Town 6
We tag our nodes with town names, and by using taxonomy term id as argument in our view, we can easily list all stories from any municipality.
Now we would like to add a new feature to our view: Also list news from the neighbouring municipality. Municiplaity Y is a Neghbour of Municipality Z, and we added this relation to the taxonomy term.
So now we can show all stories from Y by choosing using Taxonomy Depth argument. We can also show all stories, by using the Taxonomy Related terms argument.
But how to show all nodes from both Y and its sibling Z with views?
You should change the validator of the views argument to PHP code. Then, in the validator field you will be able to change the argument dynamically. This way, having the tid you can get all the related terms.
set the Action to take if argument is not present to "display empty text" ;
on validator options, set the validator to "PHP Code";
in the code:
get the tid using arg(1);
use taxonomy_get_related($tid) to get the related terms;
build a string in with the syntax "tid+related_tid+related_tid+related_tid" to return as argument;
redefine $handler->argument as the built string;
finally, set the Allow multiple terms per argument as True
Here's an example code to insert in the php code validation form:
$tid = arg(1);
$result = strval($tid);
$related = taxonomy_get_related($tid);
foreach($related as $i){
if (intval($i)>0){
$result.="+".$i;
}
}
$handler->argument = $result;
return $result;
I'm trying to find products that are in two categories.
I've found an example to get products that are in category1 OR category2.
http://www.alphadigital.cl/blog/lang/en-us/magento-filter-by-multiple-categories.html
I need products that are in category1 AND category2.
The example in the blog is:
class ModuleName_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection{
public function addCategoriesFilter($categories){
$alias = 'cat_index';
$categoryCondition = $this->getConnection()->quoteInto(
$alias.'.product_id=e.entity_id AND '.$alias.'.store_id=? AND ',
$this->getStoreId()
);
$categoryCondition.= $alias.'.category_id IN ('.$categories.')';
$this->getSelect()->joinInner(
array($alias => $this->getTable('catalog/category_product_index')),
$categoryCondition,
array('position'=>'position')
);
$this->_categoryIndexJoined = true;
$this->_joinFields['position'] = array('table'=>$alias, 'field'=>'position' );
return $this;
}
}
When I'm using this filter alone it perform OR query on several categories.
When I combine this filter with prepareProductCollection of Mage_Catalog_Model_Layer
it somehow remove the filter effect.
How can I change the filter to AND and combine it with prepareProductCollection?
Thanks
Thanks
This code will allow you to filter by multiple categories but avoid completely killing performance if you had to perform multiple collection loads:
$iNumberFeaturedItems = 4;
$oCurrentCategory = Mage::registry('current_category');
$oFeaturedCategory = Mage::getModel('catalog/category')->getCollection()
->addAttributeToFilter('name','Featured')
->getFirstItem();
$aFeaturedCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'price', 'small_image', 'url_key'), 'inner')
->addStoreFilter()
->addCategoryFilter($oFeaturedCategory)
->addCategoryIds();
The first step is to get a collection of products for one category (in this case, a Featured category). Next step is to get the IDs of the products, notice that this does NOT perform a load (ref Mage_Core_Model_Mysql4_Collection_Abstract::getAllIds())
$aFeaturedProdIds = $aFeaturedCollection->getAllIds();
shuffle($aFeaturedProdIds); //randomize the order of the featured products
Then get the IDs for a second category:
$aCurrentCatProdIds = $oCurrentCategory->getProductCollection()->getAllIds();
And intersect the arrays to find product IDs that exist in both categories:
$aMergedProdIds = array_intersect($aFeaturedProdIds,$aCurrentCatProdIds);
For this particular use case, we loop until we have sufficient intersecting products, traversing up the category tree until we find a large enough match (but stopping at root category!):
while(count($aMergedProdIds) < $iNumberFeaturedItems && $oCurrentCategory->getId() != Mage::app()->getStore()->getRootCategoryId()):
$oCurrentCategory = $oCurrentCategory->getParentCategory();
$aParentCatProdIds = $oCurrentCategory->getProductCollection()->getAllIds();
$aMergedProdIds = array_intersect($aFeaturedProdIds,$aParentCatProdIds);
endwhile;
Finally, filter our initial collection by the IDs of the intersecting products, and return.
$aFeaturedItems = $aFeaturedCollection->addIdFilter(array_slice($aMergedProdIds,0,$iNumberFeaturedItems))->getItems();
return $aFeaturedItems;
I am also working on this to no avail, it was available in magento 1.3 using the attribute filter with finset on the category_ids column, however this was moved into the index table from the entity table and now no longer works.
There is one possible solution, but requries an override function which I found here
But this solution is far from ideal.
I think that it will be enough to call addCategoryFilter() twice on your product collection - once for each category. I have not tested it though, so might be wrong.
I am working on a grid example in flex using advanced grid control.
I know we can easily group data by specifying the field name.
At the group node level, other than the gorup name I want to be able to show data in the rest of the cells ( calculated data ) and I am looking for some dataRowBound event or similar to be able to hook some data in it.
Example: Grid displaying list of towns grouped by state. At the group level ( for each state) I want to show the total number of towns in each state. Here how can i show the total number in the town column.
You can do this by providing the data like this
<trade TrdId="Trade 1 o" col="0xCC9999" cmenu="YNYNYNYNYNYNYNY" AgreementId="1234">
<trade TrdId="Trade 1.1" col="0xCC9999" cmenu="YNYNYNYNYNYNYNY" AgreementId="1234">
</trade>
<trade TrdId="Trade 1.2"col="0xCC9999" cmenu="YYYYYYYYNYNYYYY" AgreementId="1234">
</trade>
</trade>
And adding columns which read this data like
advancedDataGridColumn.dataField="#TrdId"
so on...
protected override function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void{
var XMLdata:XML=rowNumberToData(dataIndex) as XML;
if(XMLdata!=null){
if(XMLdata.attribute(Constants.col) != undefined && XMLdata.attribute(Constants.col) != ""){
color=XMLdata.attribute(Constants.col);
}else{
color=0xFFFFFF;
}
}
super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);
}
this is best method to get data out of grid and do some processing...