October 2017
Intermediate to advanced
566 pages
14h 31m
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 ...Read now
Unlock full access