March 2019
Intermediate to advanced
580 pages
15h 3m
English
Now that we have our batch definition in place, we are missing those three callback methods we are referencing in it. So, let's see the first one:
/** * Batch operation to remove the products which are no longer in the list of * products coming from the JSON file. * * @param $products * @param $context */ public function clearMissing($products, &$context) { if (!isset($context['results']['cleared'])) { $context['results']['cleared'] = []; } if (!$products) { return; } $ids = []; foreach ($products as $product) { $ids[] = $product->id; } $ids = $this->entityTypeManager->getStorage('product')->getQuery() ->condition('remote_id', $ids, 'NOT IN') ->execute(); if (!$ids) { $context['results']['cleared'] = []; return; } $entities ...