Jump to content

Update selling price


raitiamine

Recommended Posts

Hello everyone,

 

I create a small script that will update the sales price of products according to the purchase price by applying a different margin for each tranche.

 

example:

 

if the purchase price is between 0 and 100 € add a margin of 20%.

if the purchase price is between 100 and 200 € add a margin of 18%.

if the price is between 200 and 400 euros, applying a margin of 14%

so ...

 

the problem is that I run the script that the sales prices of the shop goes to 0 € regardless of the purchase price.

 

Then I turn to you to correct me because I am a beginner in PHP / MYSQL.

 

This is the script:

 

<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=ma_base', 'utilisateur', 'mot de passe');

// Selection des produits
$rep = $bdd->query('SELECT * FROM ps_product');

while ($data = $rep->fetch())
{

	// Si le prix est entre 0 et 50 euros, application d'une marge de 20%
	if ( $data['wholesale_price'] >= 0 AND $data['wholesale_price'] <= 50 )
		{
			$prix = $data['wholesale_price'] + $data['wholesale_price'] * 20/100;
			$bdd->exec('UPDATE ps_product SET price = $prix');
		}

	// Si le prix est entre 50 et 100 euros, application d'une marge de 18%
	if ( $data['wholesale_price'] > 50 AND $data['wholesale_price'] <= 100 )
		{
			$prix = $data['wholesale_price'] + $data['wholesale_price'] * 18/100;
			$bdd->exec('UPDATE ps_product SET price = $prix');
		}

	// Si le prix est entre 100 et 200 euros, application d'une marge de 16%
	if ( $data['wholesale_price'] > 100 AND $data['wholesale_price'] <= 200 )
		{
			$prix = $data['wholesale_price'] + $data['wholesale_price'] * 16/100;
			$bdd->exec('UPDATE ps_product SET price = $prix');
		}

	// Si le prix est entre 200 et 400 euros, application d'une marge de 14%
	if ( $data['wholesale_price'] > 200 AND $data['wholesale_price'] <= 400 )
		{
			$prix = $data['wholesale_price'] + $data['wholesale_price'] * 14/100;
			$bdd->exec('UPDATE ps_product SET price = $prix');
		}

	// Si le prix est entre 400 et 600 euros, application d'une marge de 12%
	if ( $data['wholesale_price'] > 400 AND $data['wholesale_price'] <= 600 )
		{
			$prix = $data['wholesale_price'] + $data['wholesale_price'] * 12/100;
			$bdd->exec('UPDATE ps_product SET price = $prix');
		}

	// Si le prix est entre 600 et 1000 euros, application d'une marge de 10%
	if ( $data['wholesale_price'] > 600 AND $data['wholesale_price'] <= 1000 )
		{
			$prix = $data['wholesale_price'] + $data['wholesale_price'] * 10/100;
			$bdd->exec('UPDATE ps_product SET price = $prix');
		}			

	// Si le prix est superieur à 1000 euros, application d'une marge de 8%
	if ( $data['wholesale_price'] > 1000 AND $data['wholesale_price'] <= 10000 )
		{
			$prix = $data['wholesale_price'] + $data['wholesale_price'] * 8/100;
			$bdd->exec('UPDATE ps_product SET price = $prix');
		}		

}
$rep->closeCursor();	

}
catch (Exception $e)
{
       die('Erreur : ' . $e->getMessage());
}


?>

 

thank you

Link to comment
Share on other sites

  • 2 years later...

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