Configurable products not searchable in Magento - 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.

Related

magento same product with many quantity different size change one time

I have a little experience in magento. All my products have custom size in option.
All products have different sizes and different prices.
Customer adds one product with quantity 5 to cart. So 5 products of this size are added to cart. When the customer adds another product with different size all products in cart change to this size.
How can i prevent this behavior?
Unless you're doing this programmatically (that is writing the code), there's no way to do this.
When Magento adds a product, it first looks into the quote / shopping cart to see if one already exists. If one does, it pulls that one and adds to the quantity. There is no way to turn this off.
Programmatically, you very manually add an item to a shopping cart. This is how...
$cart = Mage::getSingleton("checkout/cart");
foreach ($products_to_add as $product_id => $custom_options) {
$product = Mage::getModel("catalog/product")->load($product_id);
$options = new Varien_Object(array("options" => $custom_options,
"qty" => 1));
// some products may result in multiple products getting added to cart
// I beleive this pulls them all and sets the custom options accordingly
$add_all = $product->getTypeInstance(true)
->prepareForCartAdvanced($options, $product, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL);
foreach ($add_all as $add_me) {
$item = Mage::getModel('sales/quote_item');
$item->setStoreId(Mage::app()->getStore()->getId());
$item->setOptions($add_me->getCustomOptions())
->setProduct($add_me);
$item->setQty(1);
$cart->getQuote()->addItem($item);
}
}
// when done adding all the items, finally call save on the cart
$cart->save();

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
}

Hide (configurable) products with attribute

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...

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/>";
}

Magento brands by categories: show brand link

I'm setting up a webshop for a client in Magento.
He works a lot with very specific brands, so I wanted to make specific brands pages (for SEO purposes).
I followed the suggestion mentioned here: Mangento Shop By Brand to make categories out of brands.
It all works great, I can access my pages like example.com/brands/brandname.
But now, when in a products view, I want to link to that brand page.
How can I get a list of the categories for that product, or even the specific subcategory.
I thought about filtering categories by their parent_id (my brands page itself). But haven't got a clue how to go about doing it.
I found som info here but doesn't seem to work for my Magento (1.4.1.1)
It seems to do the work: Aitoc commercial module to shop by brand
Or I tried this code with Magento 1.4.1 which display the list/url of category/ies that the product belongs to, inspired of the link you provided and it works, put it in a block to allow the template to display the url:
public function getProductUrl($productId){
$product = Mage::getModel('catalog/product')->load(productId);
$currentCatIds = $product->getCategoryIds();
if ($currentCatIds) {
$categoryCollection = Mage::getResourceModel('catalog/category_collection')->addAttributeToSelect('name')
->addAttributeToSelect('url')
->addAttributeToFilter('entity_id', $currentCatIds)
->addIsActiveFilter();
foreach ($categoryCollection->getItems() as $item) {
/*echo $item->getName();
echo $item->getUrl();
echo '<br>';*/
if($item->getUrl()) return $item->getUrl();
}
}
}

Resources