Jump to content

Products that can not be bought alone


jimbojetson

Recommended Posts

I am developing a flower shop for a customer, and they have wines, balloons and cards that cannot be bought on their own, but can only be bought along with flower displays.
SO, if someone orders a Balloon on its own, I need to be able to stop the cart from validating.

Can anyone suggest a way to do this?

Link to comment
Share on other sites

thats an interesting idea
but, what i'm thinking of doing - is adding a new field to the products called 'addon' ,and in the order page, check that products with no addon tag are present along with the products that are tagged as an 'addon'. if not, then dont allow validation of the cart, and display a message.
only problem is, I'm struggling to find the right pieces of code to change.

Link to comment
Share on other sites

Well, I managed to crack this problem
I think this could be a useful standard feature in prestashop. not sure if anyone else would want it.
Could be useful for clothing accessories shops, where some small items cant be bought on their own - or for a fast food outlet to stop people buying side dishes without a main .

created a new function in Cart.php to check that items in the cart are marked as addons, and checks that non add-on items are present in the cart - public function checkAddons()
{
$notAddonprods = 0;
$Addonprods = 0;
foreach ($this->getProducts() AS $product) {
if($product['addon'] == 0) {
$notAddonprods +=1;
}

$Addonprods +=$product['addon'];
}

if($Addonprods >= 1 && $notAddonprods == 0) {
return false;
} else {
return true;
}
}

------ Then I added a couple of lines in order.php to display an error message if there are 'add on' items in the cart, with no other products -
/* If some products have disappear */
if (!$cart->checkQuantities())
{
$step = 0;
$errors[] = Tools::displayError('An item in your cart is no longer available, you cannot proceed with your order');
}
if (!$cart->checkAddons())/*Added by JD September 2010 */
{
$step = 0;
$errors[] = Tools::displayError('The item(s) in your cart can only be purchased as add-ons to other products');
}


You will also need to change the query in getProducts() in cart.php to return the 'addon' column from the product table...
make sure you add the column 'addon' to the ps_product table as Boolean.

Set the 'addon' value to 1 on products that cannot be purchased on their own (In our case - balloons that must be bought with a flower arrangement).

I added some code to AdminProducts.php to maintain the value 'addon' on each product.

All done !!!

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