- Posts: 1184
- Thank you received: 13
Add the same price in all products automatically
2 years 11 months ago - 2 years 11 months ago #355578
by verzevoul
Add the same price in all products automatically was created by verzevoul
-- HikaShop version -- : 4.7.5
-- Joomla version -- : 3.10.12
Hello!
Is there a way to add the same price in all the products with a mass action or automatically somehow else?
My question is based on this
Thank you
-- Joomla version -- : 3.10.12
Hello!
Is there a way to add the same price in all the products with a mass action or automatically somehow else?
My question is based on this
Thank you
Last edit: 2 years 11 months ago by verzevoul.
Please Log in or Create an account to join the conversation.
2 years 11 months ago #355581
by nicolas
Replied by nicolas on topic Add the same price in all products automatically
Hi,
I don't think you can add a price to products with a mass action.
You can only update existing prices.
The only solution would be to use a "run PHP code" action with something like that:
Beware that this will forcefully delete all the prices of the products / variants matching the mass action and add this 0.001 price to them. So before running that action, make sure you test the filters of your mass action with a "display the results" action as this price adding action can't be reversed automatically (unless you run another mass action with a PHP code action.
I don't think you can add a price to products with a mass action.
You can only update existing prices.
The only solution would be to use a "run PHP code" action with something like that:
Code:
$class = hikashop_get('class.product');
$product = new stdClass();
$product->prices = array();
$price = new stdClass();
$price->price_currency_id = 1; // replace 1 by the id of your currency
$price->price_value = 0.0001;
$product->prices []= $price;
$class->updatePrices($product, {product.product_id});
The following user(s) said Thank You: verzevoul
Please Log in or Create an account to join the conversation.
2 years 11 months ago #355759
by verzevoul
Replied by verzevoul on topic Add the same price in all products automatically
Hello !
Running the code
$class = hikashop_get('class.product');
$product = new stdClass();
$product->prices = array();
$price = new stdClass();
$price->price_currency_id = 1; // replace 1 by the id of your currency
$price->price_value = 0.0001;
$product->prices []= $price;
$class->updatePrices($product, {product.product_id});
I get
Action PHP code is wrong: syntax error, unexpected token "{", expecting ")"
Running the code
$class = hikashop_get('class.product');
$product = new stdClass();
$product->prices = array();
$price = new stdClass();
$price->price_currency_id = 1; // replace 1 by the id of your currency
$price->price_value = 0.0001;
$product->prices []= $price;
$class->updatePrices($product, {product.product_id});
I get
Action PHP code is wrong: syntax error, unexpected token "{", expecting ")"
Please Log in or Create an account to join the conversation.
2 years 11 months ago #355760
by verzevoul
I then tried
$class = hikashop_get('class.product');
$product = new stdClass();
$product->prices = array();
$price = new stdClass();
$price->price_currency_id = 1;
$price->price_value = 0.0001;
$product->prices []= $price;
$class->updatePrices($product, (product.product_id));
but I get
Error
Action PHP code is wrong: Undefined constant "product"
Replied by verzevoul on topic Add the same price in all products automatically
verzevoul wrote: Hello !
Running the code
$class = hikashop_get('class.product');
$product = new stdClass();
$product->prices = array();
$price = new stdClass();
$price->price_currency_id = 1; // replace 1 by the id of your currency
$price->price_value = 0.0001;
$product->prices []= $price;
$class->updatePrices($product, {product.product_id});
I get
Action PHP code is wrong: syntax error, unexpected token "{", expecting ")"
I then tried
$class = hikashop_get('class.product');
$product = new stdClass();
$product->prices = array();
$price = new stdClass();
$price->price_currency_id = 1;
$price->price_value = 0.0001;
$product->prices []= $price;
$class->updatePrices($product, (product.product_id));
but I get
Error
Action PHP code is wrong: Undefined constant "product"
Please Log in or Create an account to join the conversation.
2 years 11 months ago #355765
by nicolas
Replied by nicolas on topic Add the same price in all products automatically
Hi,
Change {product.product_id} to {product_id} and it should help.
Change {product.product_id} to {product_id} and it should help.
The following user(s) said Thank You: verzevoul
Please Log in or Create an account to join the conversation.
Time to create page: 0.179 seconds