Answer the question
In order to leave comments, you need to log in
How to increase % depending on id?
Good day to all!
Please help with the issue of increasing the price for a specific id. When you run the php file, an XML file is generated and data is displayed for each product.
We need to make sure that a percentage is added to each category and a new value is displayed.
There is the following data:
$price = CPrice::GetBasePrice($arItem['ID']); // price is pulled from the database.
$arBlocks = array(45, 44, 2, 43, 8, 9, 99); // numbers act as category ids.
foreach ($arBlocks as $IBLOCK_ID)
There are categories of goods and for each of the categories a certain percentage must be added to the amount. I understand that we should make a new variable for them.
$newPrice = $price;
switch ($IBLOCK_ID) {
case 45:
(int)$price = 1.10 * (int)$newPrice;
break;
case 44:
(int)$price = 1.20 * (int)$newPrice;
break;
case 2:
(int)$price = 1.30 * (int)$newPrice;
break;
case 43:
(int)$price = 1.25 * (int)$newPrice;
break;
case 8:
(int)$price = 1.30* (int)$newPrice;
break;
case 9:
(int)$price = 1.20 * (int)$newPrice;
break;
case 99:
(int)$price = 1.10 * (int)$newPrice;
break;
}
write_to_file($file, ' '.$price['PRICE'].'');
Tried the option above, doesn't work. Please advise what can be done in such a situation?
Thank you!
Answer the question
In order to leave comments, you need to log in
foreach ($arBlocks as $IBLOCK_ID) {
$multiplier = getPriceMultiplierByBlock($IBLOCK_ID);
$newPrice = $price * $multiplier;
// сохраняйте
}
function getPriceMultiplierByBlock($blockId) {
$multipliers = [
2 => 1.30,
8 => 1.30,
9 => 1.20,
43 => 1.25,
44 => 1.20,
45 => 1.10,
99 => 1.10,
// ...
];
return isset($multipliers[$blockId])
? $multipliers[$blockId]
: 1; // если множитель не указан - единица
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question