How to create configuarable product programatically - magento

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
}

Related

magento variable for product detail view

is there a variable to check if the product detail view (view.phtml) is used?
Why do I need this?
Price.phtml is used in product overview and product detail view also. I want to add a ifelse function when the price is shown on product detail view cause I want some more information.
Regards
Matt
Yup this is quite easy to achieve;
$pageIdentifier = Mage::app()->getFrontController()->getAction()->getFullActionName();
if($pageIdentifier == 'catalog_product_view') {
// Do something on product view page only
echo 'This is a product view page';
}

Creating slider or carousel for bundle product in magento?

I want to create a bundle products for my estore but the bundle product has more than 50 products
So i want to add carousel or slider to these product. I tried adding some sliders but it is not working??
Please suggest me with some ideas.
Got this code from inchoo, so should work
$bundled_product = Mage::getModel('catalog/product')->load(YOUR_BUNDLED_PRODUCT_ID);
$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
$bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
);
$bundled_items = array();
foreach($selectionCollection as $option)
{
$bundled_items[] = $option->product_id;
}
print_r($bundled_items);
$bundled_items has all the product ids, so you can simple load the product, and get all the detailed info. So Simply provide the data as per the need of the carousel.
To load the product
Mage::getModel('catalog/product')->load(PUT_ID_HERE);

magento - how to show only configurable product in main category, simple product in sub-category

I want to know how can I do this. I want to when i click main category, just show configurable product in page, and when i click sub-category, show simple product in page. Please help me in this, it will be really appreciated.
Thanks
You can check category level and then can display configurable product in it
if($category->getLevel() == 2){
$_productCollection1 = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('type_id','configurable');
foreach ($_productCollection1 as $product1) {
echo $product1->getName();
}
}
Hope this will help

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.

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

Resources