Add the same price in all products automatically

  • Posts: 1027
  • Thank you received: 11
  • Hikashop Business
6 months 3 weeks ago #355578

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

Last edit: 6 months 3 weeks ago by verzevoul.

Please Log in or Create an account to join the conversation.

  • Posts: 81562
  • Thank you received: 13071
  • MODERATOR
6 months 3 weeks ago #355581

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:

$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});
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.

The following user(s) said Thank You: verzevoul

Please Log in or Create an account to join the conversation.

  • Posts: 1027
  • Thank you received: 11
  • Hikashop Business
6 months 2 weeks ago #355759

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 ")"

Please Log in or Create an account to join the conversation.

  • Posts: 1027
  • Thank you received: 11
  • Hikashop Business
6 months 2 weeks ago #355760

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.

  • Posts: 81562
  • Thank you received: 13071
  • MODERATOR
6 months 2 weeks ago #355765

Hi,

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.061 seconds
Powered by Kunena Forum