2

I need to write a cron job to update my products inventory and price hourly.

The variables are these.

I have 6000 products with their own IDs which my accounting system uses (not magento).

These 6000 turn into 31,000 products. The reason for this is they are car parts, so a Mazda 3 may use the same part as a Honda civic, users on my site will be searching by make, model, and year (all attributes). The only way I could figure out how to do this by importing 31,000 different parts (so they have 31,000 magento IDs).

So I have also imported my accounting system ID as an attribute (my_part_id) which all products have.

So I would like my cron to search for all products which have my_part_id and update the qty and price.

Can someone please point me in the right direction to get this done? I am very comfortable using PHP and MYSQL, I just don't fully understand the Magento Database yet and don't want to mess up any table relationships that I don't know about.

3
  • Got any code implemented yet ? – Prateek Jun 30 '16 at 13:49
  • hello, not yet, I don't know where to start looking. I basically need a way to inner join products to attributes using an attribute value, then inner join that to product inventory – Justin Blayney Jun 30 '16 at 15:46
  • If you are comfortable with PHP and SQL, take a look at here blog.magepsycho.com/…, this might give you a head start. Please check in a dev environment first though. – Prateek Jul 1 '16 at 12:24
0

I have to do something similar in one of my Magento2 projects, I have to update product price and quantity but based on product id.

I have used public function updateAttributes($productIds, $attrData, $storeId) in file vendor/magento/module-catalog/Model/Product/Action.php to update price.

For updating the quantity, I have used the following code in my custom module.

$product = $this->productFactory->create()->load($productId);
$product->setStockData(['qty' => $newqty, 'is_in_stock' => $newss]);
$product->save();

You can modify the code according to your requirement.
I hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.