Jump to content

Need to set limit to choose one product from the list of products in category.


TOP10

Recommended Posts

please, help!
 

Problem: on certain categories of goods in online-shop we need to set limit to choose one product from the list of products in category.

 

Example: We have category HATS and we have 10 hats to choose. Customer have to choose one (of his choice) to put in shopping cart. If customer tries to choose second product (hat), this action has to be ignored and a notice should be shown that he has to choose one product only. Something similar was done in СAVЕBOX[dot]CОM, but unfortunately they are closed.

 

If someone could help and advise the solution or the way where to look for a solution, thanks in advance!

 

 

Link to comment
Share on other sites

You should explore the function processChangeProductInCart() from /controllers/front/CartController.php

 

Here you can implement your logic and if there already is a hat in the cart, then for the second one display an error message.

Link to comment
Share on other sites

controllers/front/CartController.php,  line: 112. It's still not quite what I wrote above. Help me please

if (count($customization_product))
        {
            $product = new Product((int)$this->id_product);

            $total_quantity = 0;
            foreach ($customization_product as $custom)
                $total_quantity += $custom['quantity'];

            if ($total_quantity < $product->minimal_quantity)
                $this->ajaxDie(Tools::jsonEncode(array(
                        'hasError' => true,
                        'errors' => array(sprintf(Tools::displayError('You must add %d minimum quantity', !Tools::getValue('ajax')), $product->minimal_quantity)),
                )));
            /* HACK start */
            if ($total_quantity > $product->minimal_quantity)
                $this->ajaxDie(Tools::jsonEncode(array(
                        'hasError' => true,
                        'errors' => array(sprintf(Tools::displayError('You must add %d maximum quantity', !Tools::getValue('ajax')), $product->minimal_quantity)),
                )));
            /* HACK end */

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