Hide (configurable) products with attribute - magento

I'm working on a Magento website, and what I would like to do is the following: I created an attribute to hide certain products. On a grid view page, I'm using the following code to exclude them from the list:
<?php if ($_product->getAttributeText('hideproduct')):?>
<?php else: ?>
Basically, it's just saying that when 'hideproduct' shows up, don't show anything.
This works for simple products, but for configurable products, it's a bit more complex, and it doens't seem to work with this. Let's say that I want to hide a product with a certain color, it always keeps appearing in the dropdown menu of the configurable product.
Does anyone have a solution for this?

This is what i did for one of my task (if there is a better way please let me know)
You have to extend Mage_Catalog_Block_Product_View_Type_Configurable for this purpose.
In it
public function getAllowProducts()
{
if (!$this->hasAllowProducts()) {
$products = array();
$allProducts = $this->getProduct()->getTypeInstance(true)
->getUsedProducts(null, $this->getProduct());
foreach ($allProducts as $product) {
if ($product->isSaleable()) {
if(!$product->getEcoReport())
{
$products[] = $product;
}
}
}
$this->setAllowProducts($products);
}
return $this->getData('allow_products');
}
eco_report is my attribute label.
So this is how it works... if for a simple product ( of a particular configurable product) if attribute eco_report is set then that product wont show in the configurable product's drop down list (on view page).
So all simple product's eco_report attribute has to be set so that it wont be shown on the configurable product's dropdown...

Related

Configurable products not searchable in Magento

My site has a need to have all products as configurable with no associated products (for now). So the site is mostly used as a catalog. We use configurable as opposed to simple products because we anticipate in the future we will add the associated products.
However, I notice that configurable products without associated products are not searchable. I tried to work around this by looking at this piece of code inside the Mage_CatalogSearch_Model_Resource_Search_Collection class.
// search in catalogindex for products as part of configurable/grouped/bundle products (current store)
$where = array();
foreach ($options as $option) {
$where[] = sprintf('(attribute_id=%d AND value=%d)', $option['attribute_id'], $option['option_id']);
}
if ($where) {
$selects[] = (string)$this->getConnection()->select()
->from($resource->getTableName('catalogindex/eav'), 'entity_id')
->where(implode(' OR ', $where))
->where("store_id={$storeId}");
}
I tried to comment out this code but still returns empty. Which code should I comment out?
Thank you
Ensure that the visibility is set to "Catalog, Search" and then under Inventory select "In stock" under stock availability or override the "Manage Stock" setting to "No".
Then of course ensure that indexes and cache are up to date.

How to create configuarable product programatically

I want to import configurable products in magento through xml. I have imported simple products.To create configurable product, I followed the process given here http://www.magentocommerce.com/boards/viewthread/46844/.
It works. If I remove
$data=array('5791'=>array('0'=>array('attribute_id'=>'491','label'=>'vhs','value_index'=>'5','is_percent'=>0,'pricing_value'=>'')),'5792'=>array('0'=> array('attribute_id'=>'491','label'=>'dvd','value_index'=>'6','is_percent'=>0,'pricing_value'=>'')));
$product->setConfigurableProductsData($data);
Still it works. and its good for me. But my problem is this code:
$data = array('0'=>array('id'=>NULL,'label'=>'Media Format','position'=> NULL,'values'=>array('0'=>array('value_index'=>852,'label'=>'vhs','is_percent'=>0,
'pricing_value'=>'0','attribute_id'=>'182'),'1'=>array('value_index'=>853,'label'=>'dvd',
'is_percent'=>0,'pricing_value'=>'0','attribute_id'=>'182')
),'attribute_id'=>182,'attribute_code'=>'media_format','frontend_label'=>'Media Format',
'html_id'=>'config_super_product__attribute_0'));
Can't i use just $product->getTypeInstance()->setUsedProductAttributeIds(array(491));
to set super-Attributeid =491 for configurable product ? Why the detail of attribute is required here?
Can anybody help me to find easiest way to create configurable product programmatically.
you have to see this link this is easiest way to create configurable product,
http://blog.omnisubsole.com/2009/07/01/configurable-products-in-magento/
goto app/design/frontend/default/your thme/template/catalog/product then open list.phtml
$product=Mage::getModel('catalog/product')->load($product_id);
$productType=$product->getTypeID();
//Simple Product
if($productType == 'simple')
{
//get simple product code here
}
//Configurable Product
if($productType == 'configurable')
{
//get Configurable Product code here
}

Directly go to Product Detail page on click the category?

In my store, one of the category has only one product. Is it possible to take the user directly to the product detail page of this one product whenever they click this category in the nav bar? i want to use some code to get this?
Put this in the product grid or list foreach loop in /app/design/frontend/default/[template]/template/catalog/product/list.phtml
<?php if ($_productCollection->count() == 1) {
$url = $_product->getProductUrl();
Mage::app()->getFrontController()->getResponse()->setRedirect($url); }
?>

magento tracking pixel

There are two variables which are required in the tracking pixel which needs to be placed on category, product info, cart and confirmation page.
I've managed to get the Prod list and Prod working, however, the second two are causing me problems.
I can echo out the sku in the cart, however, the products are configurable products so it's duplicating the sku in the output. The code I'm using is below:
<?php
// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();foreach($items as $item) { echo ''.$item->getSku().' ';}
?>
How do i change this to just display the one configurable SKU?
The second element is the Category name that the product exists in, Any one got any ideas on that? I've tried multiple variations but they've either broke the page or returned nothing.
Any help would be appreciated. If someone could also give me examples of how these would work on the confirmation page as well, that would be great.
Thanks for your help.
Check for the products visibility (simple products attached to a configurable would not be visible):
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item) {
if ($item->getProduct()->isVisibleInSiteVisibility()) {
echo ''.$item->getSku().' ';
}
}
With regards to the category name, a product can appear in multiple categories so im not sure how you want to handle that. Also, there is a concern that you are beginning to duplicate code across several template files. You will want to consider moving this all out to a block.
Anyway, to get the category names that the product belongs to here is at least one method of doing this...
$categoryCollection = $item->getProduct()->getCategoryCollection()
->addAttributeToSelect('name');
foreach($categoryCollection as $category) {
echo $category->getData('name') . "<br/>";
}

How to display Magento Custom Options Individually

My Magento site has a product which has a few Custom Options, one text, one file upload and four drop down lists.
The design of the site dictates that I need to show these options throughout the product view page and not all in one group.
Is there a function that I can call to return the HTML of a single Custom Option?
There are ways to do this that are tantamount to cheating.
Your shop requires javascript to operate and there is a lot you can do with Prototype before the page renders, by using the on dom:loaded event. You can attach your custom options to wherever you want in the DOM, or you can hide them and put something else where you want it on the page that updates the form element. You may want to do this if you have to capture a colour name but don't want to put oodles of colours on every product - a textbox can go on the product and your control can write to it.
The benefit of some $$('cheating') is that you don't have to go too deep into Magento code for what is a 'design consideration'.
I didn't understand correctly about group. If you mean category then ;
create a new attribute set which this attribute set should contain attributes that you want to show. After that, when you create a product, select this attribute set instead of default. So that, only this attributes will be available in the specified products.
Try the following code snippets ( don't forget to change "attribute_code")
Let say, you want to show Multi Select list in your product page, in that case :
$selectArray = $this->getProduct()->getAttributeText('YOUR_ATTRIBUTE_CODE');
$endOfArray = end($selectArray);
echo "<ul class='set-some-class'>";
foreach($selectArray as $selectionItem) {
echo "<li> . $selectionItem";
if($selectionItem != $endOfArray) {
echo "</li>\n";
} else {
echo "</ul>";
}
}
For page other than product view page, in that case:
$attribute = Mage::getModel('catalog/product')->getAttribute('catalog_product', 'YOUR_ATTRIBUTE_CODE');
$options = $attribute->getSource()->getAllOptions(true, true);
$lastOption = end($options);
echo "<ul class='set-some-class'";
foreach($options as $option) {
echo $option['label'];
if($option != $lastOption) {
echo "<li>\n";
} else {
echo "</ul>";
}
}

Resources