Jump to content

Hoe kan ik de korting op het duurste product wijzigen/aanpassen?


Onedirection

Recommended Posts

Hallo,

 

Ik wou korting geven op 1 product (duurste product) als de klant 2 of meerdere producten koopt.

Hoe kan ik het aanpassen in Prestashop 1.5.3.1? Want je hebt o.a. de mogelijkheid om korting te geven op het goedkoopste product, maar niet op duurste product.

 

Weet iemand de code?

 

Alvast bedankt.

Link to comment
Share on other sites

  • 1 month later...

Hoi Onedirection,

 

 

 

In Classes/CartRule.php (maak backup voordat je veranderingen maakt!)

is de function voor 'cheapest':

 

// Discount (%) on the cheapest product

  if ($this->reduction_percent && $this->reduction_product == -1)
  {
   $minPrice = false;
   $cheapest_product = null;
   foreach ($all_products as $product)
   {
 $price = ($use_tax ? $product['price_wt'] : $product['price']);
 if ($price > 0 && ($minPrice === false || $minPrice > $price))
 {
  $minPrice = $price;
  $cheapest_product = $product['id_product'].'-'.$product['id_product_attribute'];
 }
   }

   // Check if the cheapest product is in the package
   $in_package = false;
   foreach ($package_products as $product)
 if ($product['id_product'].'-'.$product['id_product_attribute'] == $cheapest_product || $product['id_product'].'-0' == $cheapest_product)
  $in_package = true;
   if ($in_package)
 $reduction_value += $minPrice * $this->reduction_percent / 100;
  }

 

Kopier deze functie (net onder het origineel of zo verander dit in:

// Discount (%) on the most expensive product

  if ($this->reduction_percent && $this->reduction_product == -3)
  {
   $maxPrice = false;
   $most_expensive_product = null;
   foreach ($all_products as $product)
   {
 $price = ($use_tax ? $product['price_wt'] : $product['price']);
 if ($price > 0 && ($maxPrice === false || $maxPrice < $price))
 {
  $maxPrice = $price;
  $most_expensive_product = $product['id_product'].'-'.$product['id_product_attribute'];
 }
   }

   // Check if the most expensive product is in the package
   $in_package = false;
   foreach ($package_products as $product)
 if ($product['id_product'].'-'.$product['id_product_attribute'] == $most_expensive_product || $product['id_product'].'-0' == $most_expensive_product)
  $in_package = true;
   if ($in_package)
 $reduction_value += $maxPrice * $this->reduction_percent / 100;
  }

 

 

Om de nieuwe optie te kiezen, moet je de Back Office instellingenpagina aanpassen:

 

themes/<je theme folder>/templates/controllers/cart_rules/actions.tpl (maak backup voordat je veranderingen maakt!):

gedaan

<div id="apply_discount_to_div">
<label>{l s='Apply a discount to'}</label>
<div class="margin-form">
   
 <input type="radio" name="apply_discount_to" id="apply_discount_to_order" value="order" {if $currentTab->getFieldValue($currentObject, 'reduction_product')|intval == 0}checked="checked"{/if} />
 <label class="t" for="apply_discount_to_order"> {l s='Order (without shipping)'}</label>
   
 <input type="radio" name="apply_discount_to" id="apply_discount_to_product" value="specific"  {if $currentTab->getFieldValue($currentObject, 'reduction_product')|intval > 0}checked="checked"{/if} />
 <label class="t" for="apply_discount_to_product"> {l s='Specific product'}</label>
   
 <input type="radio" name="apply_discount_to" id="apply_discount_to_cheapest" value="cheapest"  {if $currentTab->getFieldValue($currentObject, 'reduction_product')|intval == -1}checked="checked"{/if} />
 <label class="t" for="apply_discount_to_cheapest"> {l s='Cheapest product'}</label>
   

<input type="radio" name="apply_discount_to" id="apply_discount_to_most_expensive" value="most_expensive" {if $currentTab->getFieldValue($currentObject, 'reduction_product')|intval == -3}checked="checked"{/if} />

<label class="t" for="apply_discount_to_most_expensive"> {l s='Most expensive product'}</label>

  

 <input type="radio" name="apply_discount_to" id="apply_discount_to_selection" value="selection"  {if $currentTab->getFieldValue($currentObject, 'reduction_product')|intval == -2}checked="checked"{/if} />
 <label class="t" for="apply_discount_to_selection"> {l s='Selected product(s)'}</label>
</div>
<div id="apply_discount_to_product_div">
 <label>{l s='Product'}</label>
 <div class="margin-form">
  <input type="hidden" id="reduction_product" name="reduction_product" value="{$currentTab->getFieldValue($currentObject, 'reduction_product')|intval}" />
  <input type="text" id="reductionProductFilter" name="reductionProductFilter" value="{$reductionProductFilter|escape:'htmlall':'UTF-8'}" style="width:400px" />
 </div>
</div>
</div>

 

Tenslotte nog de afhandeling van de gekozen radio button. Dit word in

themes/<je theme folder>/templates/controllers/cart_rules/form.js (maak backup voordat je veranderingen maakt!):

gedaan:

function toggleApplyDiscount(percent, amount, apply_to)
{
if (percent)
{
 $('#apply_discount_percent_div').show(400);
 if ($('#apply_discount_to_product').prop('checked'))
  toggleApplyDiscountTo();
 $('#apply_discount_to_cheapest').show();
 $('*[for=apply_discount_to_cheapest]').show();

$('#apply_discount_to_most_expensive').show();

$('*[for=apply_discount_to_most_expensive]').show();

 $('#apply_discount_to_selection').show();
 $('*[for=apply_discount_to_selection]').show();
}
else
{
 $('#apply_discount_percent_div').hide(200);
 $('#reduction_percent').val('0');
}

if (amount)
{
 $('#apply_discount_amount_div').show(400);
 if ($('#apply_discount_to_product').prop('checked'))
  toggleApplyDiscountTo();
 $('#apply_discount_to_cheapest').hide();
 $('*[for=apply_discount_to_cheapest]').hide();
 $('#apply_discount_to_cheapest').removeAttr('checked');

$('#apply_discount_to_most_expensive').hide();

$('*[for=apply_discount_to_most_expensive]').hide();

$('#apply_discount_to_most_expensive').removeAttr('checked');

 $('#apply_discount_to_selection').hide();
 $('*[for=apply_discount_to_selection]').hide();
 $('#apply_discount_to_selection').removeAttr('checked');
}
else
{
 $('#apply_discount_amount_div').hide(200);
 $('#reduction_amount').val('0');
}

if (apply_to)
 $('#apply_discount_to_div').show(400);
else
{
 toggleApplyDiscountTo();
 $('#apply_discount_to_div').hide(200);
}
}

 

en:

 

function toggleApplyDiscountTo()
{
if ($('#apply_discount_to_product').prop('checked'))
 $('#apply_discount_to_product_div').show(400);
else
{
 $('#apply_discount_to_product_div').hide(200);
 $('#reductionProductFilter').val('');
 if ($('#apply_discount_to_order').prop('checked'))
  $('#reduction_product').val('0');
[size=4]  if ($('#apply_discount_to_cheapest').prop('checked'))[/size]
  $('#reduction_product').val('-1');

if ($('#apply_discount_to_most_expensive').prop('checked'))

$('#reduction_product').val('-3');

 if ($('#apply_discount_to_selection').prop('checked'))
  $('#reduction_product').val('-2');
}
}

 

 

 

Ik denk dat dit het is. Ik heb het niet getest, zelfs niet op syntax fouten gecontroleerd (uit het hoofd hier in de editor veranderd), dus het kan zijn dat er iets mis gaat, of dat ik nog iets vergeten ben.

Probeer het maar eens. Het geeft in ieder geval een idee waar je moet kijken.

 

Mocht je er niet uitkomen, laat het weten, dan probeer ik het echt uit en zie wat er mis gaat.

 

Succes,

pascal

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