Exemplo n.º 1
0
 /**
  * @param Shop $shop
  * @param string[] $numbers
  * @return Product[]
  */
 public function get(Shop $shop, $numbers)
 {
     $products = $this->coreService->get($shop, $numbers);
     foreach ($products as $product) {
         $attribute = new Attribute(['my_name' => $product->getName() . ' / ' . $product->getKeywords()]);
         $product->addAttribute('swag_es_product', $attribute);
     }
     return $products;
 }
Exemplo n.º 2
0
 /**
  * @param ShopIndex $index
  * @param string[] $numbers
  * @return \string[]
  */
 public function indexProducts(ShopIndex $index, $numbers)
 {
     if (empty($numbers)) {
         return;
     }
     $products = $this->provider->get($index->getShop(), $numbers);
     $remove = array_diff($numbers, array_keys($products));
     $documents = [];
     foreach ($products as $product) {
         $documents[] = ['index' => ['_id' => $product->getNumber()]];
         $documents[] = $product;
     }
     foreach ($remove as $number) {
         $documents[] = ['delete' => ['_id' => $number]];
     }
     $this->client->bulk(['index' => $index->getName(), 'type' => ProductMapping::TYPE, 'body' => $documents]);
 }