Jump to content

Combinations Generator with Percentage (Almost Perfect)


Jhony Ranger

Recommended Posts

Good morning.

 

I Wear weeks Desiring to provide an percentage increase in between attributes and given the dilemmas that are in the "solutions" that I have researched ... there will be future problems on the day that you upgrade to newer versions of PS. So I try to touch as little as possible the core.

 

Thanks to this trick, rescued of the "kitchendraw" user from the generator of combinations you can add a percentage of the base price using values ​​of 0.01 to 0.99. The problem comes when one of the attributes does not take price (usually the first), and therefore, the price ends up leaving of those combinations to 0. Someone could give me an example of how to add the base price for this formula only when one of the attributes is 0??

 

Pardon my english.

 

Thank you very much beforehand.

 

 

File: /controllers/admin/AdminAttributeGeneratorController.php (Prestashop 1.5.6.X)



{

$myprice = (float)preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('price_impact_'.(int)$attribute)));

if (($myprice <= 1) && ($myprice > 0))

{

$price = (($price * $myprice) + $price);

}

else

{

$price += $myprice;

}

$weight += (float)preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('weight_impact'.(int)$attribute)));

}

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

  • 1 year later...
protected function addAttribute($attributes, $price = 0, $weight = 0)

{

 

 

foreach ($attributes as $attribute)

 

 

{

$miprecio = (float)preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('price_impact_'.(int)$attribute)));

 

    if (($miprecio < 1) && ($miprecio > 0))

 

  {

/** $price *= (1+$miprecio); PARA MULTIPLICACIONES*/

switch ($attributes[0]) {

    case 34:

        $price +=  3.31; /** MEDIDA A4*/

        break;

    case 35:

        $price +=  7.18; /** MEDIDA A3*/

        break;

    case 36:

        $price +=  13.81; /** MEDIDA A2*/

        break;

case 37:

        $price +=  27.62; /** MEDIDA A1*/

        break;

    case 38: 

        $price +=  55.25; /** MEDIDA A0*/

        break;

    case 39:

        $price +=  4.98; /** MEDIDA B4*/

        break;

    case 40:

        $price +=  9.39; /** MEDIDA B3*/

        break;

    case 41:

        $price +=  19.34; /** MEDIDA B2*/

        break;

    case 42:

        $price +=  38.67; /** MEDIDA B1*/

        break;

case 43:

        $price +=  77.90; /** MEDIDA B0*/

        break;

    case 44:

        $price +=  3.87; /** MEDIDA 24-30*/

        break;

    case 45:

        $price +=  6.63; /** MEDIDA 30-40*/

        break;

    case 46:

        $price +=  11.05; /** MEDIDA 40-50*/

        break;

case 47:

        $price +=  16.57; /** MEDIDA 50-60*/

        break;

    case 48:

        $price +=  26.52; /** MEDIDA 60-80*/

        break;

   

}

 

 

 

 

    }

    else

    {

 

$price +=  $miprecio;

 

 

    }

 

 

$weight += (float)preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('weight_impact_'.(int)$attribute)));

}

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