Jump to content

allow_oosp Error in Cart - Quantity Always Shows as Unavailable


janoroh

Recommended Posts

I'm currently setting up a new 1.7.8.4 installation (data migrated from 1.5.4) and have run into the following problem:

I've activated ordering of items that are not in stock in the backend. However, regardless of whether an item is in stock or not, the cart page (index.php?controller=cart&action=show) will always show an error message that the selected quantity is not available and the continue button is grayed out. If the quantity up and down arrows are clicked on that same page, the error message disappears and it's possible to proceed with the order. Does anybody know how I can get rid of that error so that customers are directly able to order without seeing the incorrect error message on the checkout page? I don't know where it's coming from.

If I turn on Debug Mode, I get the following error on that page when an item is in the cart:

 

Whoops, looks like something went wrong.

(1/1) ContextErrorException

Notice: Undefined index: allow_oosp

in Cart.php line 4095

at CartCore->checkQuantities(true)in CartController.php line 631

at CartControllerCore->areProductsAvailable()in CartController.php line 82

at CartControllerCore->init()in Controller.php line 287

at ControllerCore->run()in Dispatcher.php line 518

at DispatcherCore->dispatch()in index.php line 28

 

The relevant part of Cart.php is this one, line 4095 marked in bold:

 

/**
     * Check if product quantities in Cart are available.
     *
     * @param bool $returnProductOnFailure Return the first found product with not enough quantity
     *
     * @return bool|array If all products are in stock: true; if not: either false or an array
     *                    containing the first found product which is not in stock in the
     *                    requested amount
     */
    public function checkQuantities($returnProductOnFailure = false)
    {
        if (Configuration::isCatalogMode() && !defined('_PS_ADMIN_DIR_')) {
            return false;
        }

        foreach ($this->getProducts() as $product) {
            if (
                !$this->allow_seperated_package &&
                !$product['allow_oosp'] &&
                StockAvailable::dependsOnStock($product['id_product']) &&
                $product['advanced_stock_management'] &&
                (bool) Context::getContext()->customer->isLogged() &&
                ($delivery = $this->getDeliveryOption()) &&
                !empty($delivery)
            ) {
                $product['stock_quantity'] = StockManager::getStockByCarrier(
                    (int) $product['id_product'],
                    (int) $product['id_product_attribute'],
                    $delivery
                );
            }

            if (
                !$product['active'] ||
                !$product['available_for_order'] ||
                (!$product['allow_oosp'] && $product['stock_quantity'] < $product['cart_quantity'])
            ) {
                return $returnProductOnFailure ? $product : false;
            }

            if (!$product['allow_oosp']) {
                $productQuantity = Product::getQuantity(
                    $product['id_product'],
                    $product['id_product_attribute'],
                    null,
                    $this,
                    $product['id_customization']
                );
                if ($productQuantity < 0) {
                    return $returnProductOnFailure ? $product : false;
                }
            }
        }

        return true;
    }

 

Edited by janoroh (see edit history)
Link to comment
Share on other sites

Thank you! I was puzzled because I couldn't find any overrides, but I finally realized that it seems to be caused by @vekiaMyPresta's "Maximum product quantity per customer" module. The error disappears when the module is deactivated. I guess it might not yet be fully compatible with 1.7.8.4. or there's some other bug. Too bad that he doesn't seem to be active on the forums anymore. I'll check with their support to see if there's a fix.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...