A
A
Aljo2022-03-01 15:42:56
MODX
Aljo, 2022-03-01 15:42:56

How to change the price of all products from a certain category in minishop2?

Hello, I need to change the bulk prices for all products from the category with id 24.
Increase the price by 8%?

$product = $modx->getObject('msProduct', тут id);
$oldPrice = $product->get('price');
$product->set('price', $oldPrice  + $oldPrice*0.08);


Is this the correct code for one item? And how to write for everyone from one category?
I was told that it is possible to execute the script in console.

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Tarasov, 2022-03-01
@aljo222

$query = $modx->newQuery('msProduct');
$query->limit(10000);
$query->where(array(
    'parent' => 4, // тут ID категории
));
$docs = $modx->getCollection('msProduct',$query);
foreach($docs as $doc){
    $oldPrice = $doc->get('price');
    $doc->set('price', $oldPrice  + $oldPrice*0.08);
    $doc->save();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question