Jump to content

cart rules - i need to set a definite number of items in my cart - how?


teletype

Recommended Posts

Hello there,

 

the point is that my shop sells wine and I like to sell pack of six bottles or any multiple (12, 18, etc)

Bottles could be chosen from the whole catalog but the cart should contain 6 or multiple to be valid.

 

How can I get this result?

Is there any modules ready?

 

Thanks for your advice.

Oto Tortorella

Link to comment
Share on other sites

Could they be 6 different bottles, or must they be every time 6 of the same?

 

So, can it be any combination of wines, as long as the total order it's a multiple of any 6 'bottles'? Or always (multiples of) 6 the same 'product'.

 

 

- 1 Cabernet Merlot

- 2 Côtes de Castillon AOC

- 2 Bourgogne Pinot Noir AOC Le Renard

- 7 Givry Rouge AOC

 

OR

 

 

- 6 Cabernet Merlot

- 12 Côtes de Castillon AOC

- 24 Bourgogne Pinot Noir AOC Le Renard

- 6 Givry Rouge AOC

 

Please elaborate a little.

pascal

Link to comment
Share on other sites

You are right Pascal, it's not so clear.

 

It can be any combination of wines, but in multiple of 6.

As an examlpe:

 

1 x Taurasi 

3 x Aglianico

2 x Greco

1 x Fiano

5 x Coda di Volpe

 

That's 12 bottle, 6 + 6 and it's correct

 

If it would be:

1 x Taurasi 

3 x Aglianico

2 x Greco

1 x Fiano

 

it is 7 bottles,  6 + 1 and the system should ask the customer to remove 1 or add 5 

 

Is there any easy way to achive it?

 

Thanks

Link to comment
Share on other sites

so basically you need a logic condition at the point of checkout.

 

That condition would do something like

if ($cart->getNbProducts() % 6) {
   // The number of products is not a multiple of 6.  So you break out of the checkout process and display a message

} else {
   // The number if products is a multiple of 6, so you allow the checkout to continue

}

I don't know if there is a module that could do this, so you would need to locate the best place to perform this check.  Is it best to do it on the cart summary page before they entered the checkout process, or perhaps you hide the payment methods if the product count is not a multiple of 6

Link to comment
Share on other sites

Thanks Pascal, that's a great advice.

 

I'm using PS 1.6.0.9 with the defult theme and a 5 step checkout.

it would be nice to have a note in the cart block on the upper part of the page, another note on the cart page and then a way to block the procedure after the registration of the sustomer.

 

Where can I place the code?

 

I thank you for your time.

 

Regards

Oto Tortorella

Link to comment
Share on other sites

I would indeed add just a fixed message somewhere in your header or in the cartblock. If you want to make this header only appear when there's not a multiple of six, you need to add with the ajax code (ajax code send/receives values to server without leaving the page) etc, which is not so 'obvious'/simple...

 

So just a general message here would probably do. This you can add to either themes/<your theme folder>/header.tpl or to themes/<your theme folder>/modules/blockcart/blockcart.tpl

 

For example in blockcart.tpl, somewhere halfway the file you have the following code (add the red code):  (Make back up first!!!)

 

 

      <p class="cart-buttons">
        <a id="button_order_cart" class="btn btn-default button button-small" href="{$link->getPageLink("$order_process", true)|escape:"html":"UTF-8"}" title="{l s='Check out' mod='blockcart'}" rel="nofollow">
          <span>
            {l s='Check out' mod='blockcart'}<i class="icon-chevron-right right"></i>
          </span>
        </a>
      </p>
      <span id="six_box_cart_message">{l s='Order will be packed in boxes of 6. So order size must be (multiples of) 6 bottles. Any combination is possible' mod='blockcart'}</span> 
    </div>
  </div>
</div><!-- .cart_block -->
 

 

 

and add to themes/<your theme folder>/css/global.css this code (at the end) to center the text:

 

 

#six_box_cart_message {

    display: block;

    text-align: center;

}
 
post-455771-0-29156200-1413574141_thumb.png
 
 
The real check in summary page is some more work. You probably want to check real time if the amount of products is % 6 (modulo 6), as Bellini mentioned, and only make the proceed button available when this is the case...
 
 
I'll see what I can find. Please be patience. Coming week (Tuesday) I'm going to Singapore for some holiday. Not sure I find a solution before that time..
 
pascal.
Link to comment
Share on other sites

Hello there,

 

the point is that my shop sells wine and I like to sell pack of six bottles or any multiple (12, 18, etc)

Bottles could be chosen from the whole catalog but the cart should contain 6 or multiple to be valid.

 

How can I get this result?

Is there any modules ready?

 

Thanks for your advice.

Oto Tortorella

in your_theme/modules/blockcart/blockcart.tpl (Prestashop 1.5.6.2), modify as:

		<p id="cart-buttons">
		{if $order_process == 'order'}<a href="{$link->getPageLink("$order_process", true)|escape:'html'}" class="button_small" title="{l s='View my shopping cart' mod='blockcart'}" rel="nofollow">{l s='Cart' mod='blockcart'}</a>{/if}
			<a href="{$link->getPageLink("$order_process", true)|escape:'html'}" id="button_order_cart" class="exclusive{if $order_process == 'order-opc'}_large{/if}" title="{l s='Check out' mod='blockcart'}" rel="nofollow"><span></span>{l s='Check out' mod='blockcart'}</a>		
		</p>
		<script>
		$(document).ready(function(){
			ajaxCart.refresh();
			var cartUrl = $('#button_order_cart').attr('href');
			$("#button_order_cart, #shopping_cart").on('click', function (e) {
				e.preventDefault();	
				
				if (ajaxCart.nb_total_products > 0 && ajaxCart.nb_total_products % 6 == 0) {
					$("#six_box_cart_message").css('color','green');
					$(location).attr('href',cartUrl);
				}
				else	
					$("#six_box_cart_message").css('color','red');
			});
		});
		</script>
		<p id="six_box_cart_message" style="margin-top: 10px;font-weight: 700;background-color: white;padding: 5px;">
			{l s='Order will be packed in boxes of 6. So order size must be (multiples of) 6 bottles. Any combination is possible' mod='blockcart'}
		</p> 

in your_theme/modules/blockcart/blockcart.tpl  (Prestashop 1.6.0.8), modify as:

						<p class="cart-buttons">
							<a id="button_order_cart" class="btn btn-default button button-small" href="{$link->getPageLink("$order_process", true)|escape:"html":"UTF-8"}" title="{l s='Check out' mod='blockcart'}" rel="nofollow">
								<span>
									{l s='Check out' mod='blockcart'}<i class="icon-chevron-right right"></i>
								</span>
							</a>
						</p>
						<script>
							$(document).ready(function(){
								ajaxCart.refresh();
								var cartUrl = $('#button_order_cart').attr('href');
								$("#button_order_cart, .shopping_cart").on('click', function (e) {
									e.preventDefault();	
									
									if (ajaxCart.nb_total_products > 0 && ajaxCart.nb_total_products % 6 == 0) {
										$("#six_box_cart_message").css('color','green');
										$(location).attr('href',cartUrl);
									}
									else	
										$("#six_box_cart_message").css('color','red');
								});
							});
						</script>
						<p id="six_box_cart_message" style="margin-top: 10px;font-weight: 700;padding: 5px;">
							{l s='Order will be packed in boxes of 6. So order size must be (multiples of) 6 bottles. Any combination is possible' mod='blockcart'}
						</p> 

A check is also required on the cart page (if the client knows the url)

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

I myself wouldn't do the check in the cartblock, as the quantity of a product can be more easily adjusted in the summary using the + and -.

If you forbid the customer to go to the checkout summary and he/she wants to add another bottle of the same product, the customer then has to find the product first, then press the 'add to cart' etc. However, If you allow him/her to get to the checkout summary, her/she can just click the + or - to adjust the amount...

(Also, in 1.6.x, when adding a product, you have a pop up screen where you can directly go to checkout, or continue shopping, bypassing the cartblock... So you would need three places to add/maintain code to do the check )

 

Any way to add the check to the summary, edit file:

 

themes/<your theme folder>/js/cart-summary.js: (Make backup!!!!)

 

 

Short description: We want to make the proceed button red and when clicked not going to the next order step. We change the text when the total number of products is not modulo 6 to tell the customer it needs (a multiple of) 6 bottles to proceed. When the total amount is(a multiple of) 6, the proceed button becomes available, and clicking it will proceed to step 2 of the checkout process.

 

First we define two vars to keep the original values of the link to the next step, and the original button text..

 

To do this: at the top of the file, you have the following black code and add the red code: (Sample code from PS 1.6.0.8)

 

$(document).ready(function(){
 
  var origlink = null;
  var origtext = null;
 

 

at the end of this same function, we add some function call, to a function we will define below (find black code, and ad red code):

 

  $('#enable-multishipping').checkboxChange(
    function(){
      $('.standard-checkout').hide(0);
      $('.multishipping-checkout').show(0);
    },
    function(){
      $('.standard-checkout').show(0);
      $('.multishipping-checkout').hide(0);
    }
  );
  toggleProceed(parseInt($('#summary_products_quantity').text().replace(/[^0-9]/g, ''))); // Set proceed button correctly when the page loads for first time
 
});
 
 

 

When this is done, find in the same file the function:

    function updateCartSummary(json)

 

just above this function, add the following function code:

 

 

function toggleProceed(nbrProds)
{
  if (typeof origlink === 'undefined') {
    origlink = $('.standard-checkout').attr("href");
    origtext = $('.standard-checkout span').html();
  }
  if (nbrProds%6 !=0) {  // change 6 as needed
    if (!$('.standard-checkout').hasClass("dont_proceed")) {
      $('.standard-checkout').removeAttr("href");
      $('.standard-checkout').fadeOut(600, function() {
        $('.standard-checkout').removeClass("do_proceed").addClass("dont_proceed");
        $('.standard-checkout span').text('Please order (multiples of) 6 bottles to proceed');
        $(this).fadeTo(600, 0.7);
      });
    }
  }
  else {
    if (!$('.standard-checkout').hasClass("do_proceed")) {
      $('.standard-checkout').attr("href", origlink); 
      $('.standard-checkout').fadeOut(600, function() {
        $('.standard-checkout').removeClass("dont_proceed").addClass("do_proceed");
        $('.standard-checkout span').html(origtext);
        $(this).fadeTo(600, 1);
      });
    }
  }
}
 
 
Finally, inside the function
function updateCartSummary(json)
 
itself, find the black code and add the red function call code:
// Cart summary
$('#summary_products_quantity').html(nbrProducts + ' ' + (nbrProducts > 1 ? txtProducts : txtProduct));
 
toggleProceed(nbrProducts); // Allow only multiples of 6 products
 
if (priceDisplayMethod !== 0)
  $('#total_product').html(formatCurrency(json.total_products, currencyFormat, currencySign, currencyBlank));
else
  $('#total_product').html(formatCurrency(json.total_products_wt, currencyFormat, currencySign, currencyBlank));
 

When you're sure you made a backup(!!), save the file.

 

to finish it, we add some css to make the button red, and the text centered (for mobile screens)

edit file /themes/<your theme folder>/css/global.css, ad add at the end:

 

 
#six_box_cart_message {   // this we added already in post #7...
    display: block;
    text-align: center;
}
 
.cart_navigation a.dont_proceed {
    background: red;
    text-align: center;
}
 
.cart_navigation a.dont_proceed:hover {
    background: darkred;
    text-align: center;
}
 

save the file, add a few products, go to the summary page and play with the amounts, delete products etc.

 

 

This should do the trick, I believe. Give it a try and please let me know,

pascal.

 

P.S. link to example: here  (order some products and go to checkout, add/remove items/quantity)

Edited by PascalVG (see edit history)
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...