Magento Configurable products don't go out of stock - magento

I have the usual configurable-simple products store. Ideally I would like that a configurable products should automatically go out of stock when all of its associated products go out of stock. How ever this does not seem to happen. Am I missing something in the configuration or is this not supported?
I am using magento community 1.6.1.

Probably it's not supported. I have similar problem and I use this code to eliminate out of stock products:
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', array('eq' => 'configurable'));
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_productCollection);

sulabh
First check your inventory configuration for every product ("manage stock") should be set to true.
Then run stock reindex. It will check if every child is out of stock -> will set configurable product out of stock.

Related

How to determine if a simple product is part of a configurable product?

Im currently writing a export tool for Mage1 in order to export products from Mage1 to Mage2.
I thereby want to determine if a product in the collection is part of a configurable product.
My current collection is set up this way:
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->setPageSize(500)
->setCurPage(1)
->addAttributeToSort('sku', 'ASC')
->addAttributeToFilter('type_id', array('eq' => 'simple'))
->addAttributeToSelect('*')
->load();
First, I request only simple products right now. If I delete this line, I get every products in the shop in the collection, but In the code every product is handled like a simple product currently.
Now, following is happening:
I request the script and get my information for all simple products. In the store I use to test there are configurable products AND bundle products. I know want to know how I could determine if a product is part of a configurable or bundle article and how I could assign those "simple" products to the respective configurable products?
I generate a CSV which I can upload in Mage2 successfully, but as I already said, it only imports simple products (as desired so far).
I googled a little (https://www.google.de/search?q=get+assigned+simple+products+for+a+configurable+product&ie=utf-8&oe=utf-8&gws_rd=cr&ei=b3i8VuD6BIevswGWtbGACw) but I'm still clueless. :/ Hopefully someone here can help me with this matter.
Also, I checked this thread: Checking if a Magento product is a child of a configurable product - but I don't get what to do with the respective name. Maybe this is already the right guess?
Thanks, Max
Yes there is a way of doing so. Have a look at the model class Mage_Catalog_Model_Product_Type_Configurable, there is a function called getParentIdsByChild.
Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($productId);
It will return an empty array if no parents id's have been found.

Change Magento collection to show only grouped products

I'm trying to modify Magento (1.7.0.2) collection to show only grouped products in the product list. I've tried to do this with addAttributeToSelect or addAttributeToFilter like this
$_productCollection=$this ->getLoadedProductCollection()
->addAttributeToSelect('*')->addAttributeToFilter('type_id','grouped');
or
$_productCollection=$this ->getLoadedProductCollection()
->addAttributeToFilter('type_id', array('eq' => 'grouped'));
but it's not working now with this version of Magento.
Anybody knows how can I get it working?
Filters not being applied often happens when the production is already loaded.
Try doing a $_productCollection->clear() before you iterate across the collection. Preferably though, find a place to update the collection before it is loaded.

Magento - Updating the price of a configurable product option

Magento version 1.6.1.0. I'm attempting to write some code that will dynamically update the price of a configurable product's option. My ultimate aim is to write a module that will update the price of the configurable product's options based on the price of the children products of the configurable. The attached code pulls out all the configurable products from a catalogue and displays them along with the product options & prices and the children products' name & price. I plan to work out the difference in price between the configurable and each child product and update the price appropriate option to match. So far I have been unable to work out how to update the price of a product option.
Short version: I just need a way to update the price of a configurable product's option. Do you know how to do this?
<?php
require_once './app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(1);
// load in configurable products
$productConfig = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', 'configurable');
foreach ($productConfig as $_product)
{
// load the configurable product
$_product = Mage::getModel('catalog/product')->load($_product->getId());
echo 'Product Name';
var_dump ($_product->getName());
var_dump ($_product->getPrice());
// Collect options applicable to the configurable product
$productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute)
{
var_dump($productAttribute['label']);
foreach ($productAttribute['values'] as $attribute)
{
var_dump($attribute);
}
}
// loop through the child products
echo 'Child products';
$col = Mage::getModel('catalog/product_type_configurable')->setProduct($_product)->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($col as $simple_product)
{
var_dump($simple_product->getName());
var_dump($simple_product->getPrice());
}
}
echo '~fin';
?>
Thank you!
Well, I solved this one after quite a bit of head scratching. I don't know if I did it "right" or not.
I solved it by manually running some SQL to adjust the pricing in the catalog_product_super_attribute_pricing table. If you're going to do this, you'll need a product_super_attribute_id, which you can get from the catalog_product_super_attribute table if you have a product ID.
One caveat: If a price does not exist in the backend for an option (if the option exists, but adds £0 to the product price when selected), there will not be a record for the option in the catalog_product_super_attribute_pricing table, you'll need an insert query instead of an update in that case.
I had the same issue and I started doing the same thing: write a module to update configurable product's options.
I recently published it here: Magento Configurable Auto Pricing
I tested it just with EE 1.12 but it should work also with CE and I'd be glad if anyone wants to try it and give me any feedback or even better write his own fixes and commit them :)

product show in stock in admin order when it is in out of stock Magento

Hi i am trapped in a very strange situation, my client has enable the customers to order the products which are out of stock , the problem is when the customer place the order it shows the product in stock in order . I need to show the product status out of stock in the order so he come to know about the order item status .
Below is the settings i have in catalog-> inventory in admin
please suggest me where i am doing mistake or how can i do this
thanks
You need to modify your product.phtml inside app/design/frontend/{yourpackage}/{yourtheme}/template/catalog/product/view.phtml
Add following in your code scope for testing and checking if its not already showing out of stock .
$stockItem = Mage::getModel('cataloginventory/stock_item');
$resource = $stockItem->loadByProduct($_product->getId());
if(round($resource->getQty(),0) < 1)
{
echo "product is out of stock";
}
The above code actually tests if there is any quantity available in stock and is greater than 1. Also make a note that this will not work for the products setup as not to be managed by stock under inventory tab in product add/modify case.
Thanks

Does changing Magento SKU affect the Order History

I have a request to change the SKU for an existing product, so I am wondering if changing the SKU will affect the order history of this product. Since SKU is a global Identifier in Magento I am not sure what would be the effect of changing it. This is Magento 1.7 CE
Thanks
Order data is stored in the sales_flat_order_item and sales_flat_order tables. If you change the SKU of a product in your catalog, it will not affect the SKU of the product on already existing orders.
Regards,
Changing the SKU of an active product, and or the flat product's afterword will NOT retroactively update the sales order history.
100% sure on this.
Sales Order History
Referencing the old SKU to the "New" Sku will result in some broken behavior that must be accounted for, this especially is true in Configurable products.
Cheers,
-J
http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/catalog_database_tables

Resources