0

I need the ability to show Out of Stock variants when all variants(simple/children) under a configurable are out of stock. The default bahavior I am trying to overcome is to remove the product-options all together.

I've made the following code adjustment as a local edit to app\code\core\Mage\Catalog\Block\product\View\Type\Configurable.php to ensure out of stock variants show when the Show Out of Stock option (System > Admin > Inventory > Show Out of Stock) is set to 'Yes':

public function getAllowProducts()
{
    // check OoS display value (admin > config > inventory > stock options > display out of stock products)
    $showOos = Mage::helper('cataloginventory')->isShowOutOfStock();
    if (!$this->hasAllowProducts()) {
        $products = array();
        $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
        $allProducts = $this->getProduct()->getTypeInstance(true)
            ->getUsedProducts(null, $this->getProduct());
        foreach ($allProducts as $product) {
            // if OoS display 'Yes' show all variants
            if ($showOos === true) {
                $products[] = $product;
            // if not, filter out OoS variants
            } else if ($product->isSaleable() || $skipSaleableCheck) {
                $products[] = $product;
            }
        }
        $this->setAllowProducts($products);
    }
    return $this->getData('allow_products');
}

This works great so long as at least one variant is in stock. If all of them are set to out of stock, product-options disables at the configurable level. A few notes:

  • I started by manipulating the hasOptions() function, with no luck. I also removed this as an if condition on the view.phtml page around my 'container1' and 'container2' getChildChildHTML declarations. (originally 'if ($_product->isSaleable() && $this->hasOptions())', now commented out solely for the test) This returns the product options container itself, but does not generate the variants list.
  • Running a $product->getOptions() foreach for a configurable in view.phtml with all out of stock variants returns nothing.

I have a feeling there is something deeper I am missing. Anyone dealt with this before?

0

Add this

$defaultSkip = Mage::helper('catalog/product')->getSkipSaleableCheck();
Mage::helper('catalog/product')->setSkipSaleableCheck(true);

right above

$skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck(); 

and

Mage::helper('catalog/product')->setSkipSaleableCheck($defaultSkip);

before or after

$this->setAllowProducts($products);
  • No change. Unless I am missing something, the additional 'if' I have in this statement isn't even checking the getSkipSaleableCheck() anymore if isShowOutOfStock() is 'true'. Check below my code comment '// if OoS display 'Yes' show all variants'. It should be returning all variants regardless since it is no longer checking if $product->isSaleable() or $skipSaleableCheck. – Kevin Gardner Apr 3 '15 at 14:00
  • It appears as if the foreach itself in this statement isn't getting the list of variants when the configurable is out of stock, which is what made me think there is something else - possibly in how $allProducts is pulling the collection - that is being filtered out somehow. – Kevin Gardner Apr 3 '15 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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