1

Is there a way to update single product Sorl index programmatically? Here are a snippet from my price updating module. I need to run index update rigth after it:

$wrapper = entity_metadata_wrapper('commerce_product', $pid);
$wrapper->commerce_price->amount = $price * 100;
$wrapper->commerce_price->currency_code = $currency;
$wrapper->save();
Dmytro Sukhovoy
  • 952
  • 5
  • 17

1 Answers1

0

I don't know how you handle your solr with Drupal. I program it myself with curl... But maybe this helps you on your way...

You have 2 ways:

first way: delete the old product and add it again:

$json = '{"delete":{"query":"id:' . $articleId . '"},"commit":{}}'
$url  = 'http://solrhost/solr/yourcore/update/json';

Handle the url with curl, and the json string are your post fields

$json = '{"add":' . $json_of_article . ',"commit":{}}';
$url  = 'http://solrhost/solr/yourcore/update/json';

Handle the url with curl, and the json string are your post fields

second way: update a field in one product

$data = json_encode(array('doc' => array('id' => $articleId, 'price' => array('set' => $newPrice))));
$json = '{"add":' . $data . ',"commit":{}}';
$url  = 'http://solrhost/solr/yourcore/update/json';

I hope this helps...

Wim
  • 41
  • 3