public function eshopDetailAction(Request $request)
 {
     /** @var Eshop $eshop */
     $eshop = $this->eshopRepository->findOne([EshopMeta::SLUG => $request->attributes->get("eshop")]);
     $category = null;
     if ($request->attributes->has("category")) {
         /** @var Category $category */
         $category = $this->categoryRepository->findOneById($request->attributes->get("category"));
     }
     return $this->render("CC15Bundle:Eshop:eshopDetail.html.twig", ["eshop" => $eshop, "category" => $category, "categories" => $this->categoryRepository->findCategories($eshop, $category), "products" => $this->listingService->findProducts(ListingFilter::create()->setEshop($eshop)->setCategory($category))]);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     foreach ($this->eshopRepository->find([]) as $eshop) {
         /** @var Eshop $eshop */
         foreach ($eshop->getFeeds() as $feed) {
             $import = new Import();
             $import->setEshop($eshop)->setFeed($feed);
             $this->downloadProducer->publish($import);
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $categoryCol = $this->mongo->createCollection(CategoryMeta::SHORT_NAME);
     var_dump($categoryCol->ensureIndex([CategoryMeta::ESHOP_ID => 1, CategoryMeta::HASH => 1], ["unique" => true]));
     $productCol = $this->mongo->createCollection(ProductMeta::SHORT_NAME);
     var_dump($productCol->ensureIndex([ProductMeta::ESHOP_ID => 1, ProductMeta::ITEM_GROUP_ID => 1, ProductMeta::ITEM_ID => 1], ["unique" => true]));
     var_dump($productCol->ensureIndex(["_id" => 1, ProductMeta::V => 1], ["unique" => true]));
     $eshopCol = $this->mongo->createCollection(EshopMeta::SHORT_NAME);
     var_dump($eshopCol->ensureIndex([EshopMeta::SLUG => 1]), ["unique" => true]);
     $f = fopen($input->getArgument("csv"), "r");
     while (list($slug, $url, $feedUrl) = fgetcsv($f)) {
         $eshop = new Eshop();
         $eshop->setName($slug)->setSlug($slug)->setUrl($url)->setFeeds([(new Feed())->setId(new \MongoId())->setUrl($feedUrl)]);
         $eshopDoc = $this->eshopRepository->findAndModify([EshopMeta::SLUG => $slug], EshopMeta::toArray($eshop), ["_id"], ["upsert" => true, "new" => true]);
         var_dump($eshopDoc);
     }
 }
 public function handleMessage(Change $change, Message $message, Channel $channel)
 {
     if (!$change->getProduct()) {
         throw new \InvalidArgumentException("Badly routed message '{$message->content}' with routing key '{$message->routingKey}'.");
     }
     $product = $change->getProduct();
     /** @var Eshop $eshop */
     $eshop = $this->eshopRepository->getOneById($product->getEshopId());
     $product->setEshop($eshop);
     $categoryIds = $product->getCategoryIds();
     if (!empty($categoryIds)) {
         $product->setCategories($this->categoryRepository->find(["_id" => ['$in' => $product->getCategoryIds()]]));
     }
     if (!$this->elasticsearch->indices()->existsAlias(["name" => $this->catalogIndexAliasName])) {
         $this->initIndex();
     }
     $response = $this->elasticsearch->index(["index" => $this->catalogIndexAliasName, "type" => ProductMeta::SHORT_NAME, "id" => (string) $product->getId(), "version" => $product->getV(), "version_type" => "external_gte", "body" => ProductMeta::toObject($product, "json:")]);
     $this->log->info("Indexed Product#{$product->getId()} (v={$product->getV()}, created=" . json_encode($response["created"]) . ").");
     $channel->ack($message);
 }
 public function homepageAction()
 {
     return $this->render("CC15Bundle:Homepage:homepage.html.twig", ["eshops" => $this->eshopRepository->findEshopsForHomepage(), "products" => $this->listingService->findProducts(ListingFilter::create())]);
 }