8

I recently ran into a problem with a store, when I started noticing certain stock notification e-mails weren't being sent. All of the e-mails for simple products are fine, but when it comes to configurable products, here's my problem:

Right now, customers are able to sign up for the stock notification e-mails. The cron job runs fine, and system logically only sends them when they're actually in stock and not set to 0. The configurable products are however, always set to 0, and the simple products that belong to this configurable do the stock changing. So what happens now is, people are only able to subscribe to a product when ALL of the sizes are out of stock (so not even able to select a size they wish to receive information about), but then when the shoes for example get restocked, they don't receive a notification because the configurable (which is the product they subscribed to) is still at 0.

I'm sure I'm not the first person to run into this problem, so I was wondering if anyone has been able to work around it or find a solution?

2 Answers 2

1

It sounds like you will need to adjust your code in two places. First, where your code checks for each product whether customers are allowed to subscribe it. Second, where your code (the cron job I assume) checks stock changes for the products.

In the first instance, you could allow subscription if any of the child products are out of stock:

$allowSubscriptionForProduct = false;
if ($product->getData('type_id') == 'configurable') {
    $childProductIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($product->getId())
    foreach ($childProductIds[0] as $childProductId) {
        $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($childProductId);
        if ($stock->getData('is_in_stock') == 1) {
            $allowSubscriptionForProduct = true;
            break;
        }
    }
}
if ($allowSubscriptionForProduct === true) {
    // change a product attribute to let customers subscribe to this product. 
}

N.B.: $childProductIds has a strange structure. I would expect an array of ids, but getChildrenIds() wraps that array in another array. Hence the [0] in the foreach loop.

In the second instance, you need to go from the child product to the parent configurable product.

foreach ($simpleProductThatWasOutOfStock as $outOfStockSimpleProduct) {
    $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($outOfStockSimpleProduct->getId());
    if ($stock->getData('is_in_stock') == 1) {
        $configurableProductIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($outOfStockSimpleProduct->getId())
        foreach ($configurableProductIds as $configurableProductId) {
            // use the code that schedules/sends the email notifications 
        }
    }
}

Without the actual code that you are using, it is hard to be more precise. I hope this puts you on the right track at least.

These entries may also be useful. To check stock status:

https://stackoverflow.com/a/2703800

https://stackoverflow.com/a/31612963

Going from child product to configurable parent:

https://stackoverflow.com/a/1706297

https://magento.stackexchange.com/a/30245

0

You might need to custom code or use any extension that provides such functionality as configurable product work based on main product not as per the simple product.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.