/** * Serializes \CC15\Entity\Product to object * * @param Product $object * @param string $group * * @throws \InvalidArgumentException * * @return object */ public static function toObject($object, $group = NULL) { if ($object === null) { return null; } if (!isset(self::$groups[$group])) { throw new \InvalidArgumentException('Group \'' . $group . '\' not supported for ' . 'CC15\\Entity\\Product' . '.'); } else { $id = self::$groups[$group]; } if (!$object instanceof Product) { throw new \InvalidArgumentException('You have to pass object of class CC15\\Entity\\Product.'); } $output = array(); if (($id & 1) > 0 && isset($object->id)) { $output['_id'] = $object->id; } if (($id & 2) > 0 && isset($object->id)) { $output['id'] = (string) $object->id; } if (($id & 1) > 0) { $output['v'] = $object->v; } if (($id & 2) > 0 && isset($object->v)) { $output['v'] = $object->v; } if (($id & 1) > 0) { $output['eshopId'] = $object->eshopId; } if (($id & 2) > 0 && isset($object->eshopId)) { $output['eshopId'] = (string) $object->eshopId; } if (($id & 1) > 0) { $output['eshop'] = EshopMeta::toObject($object->eshop, $group); } if (($id & 2) > 0 && isset($object->eshop)) { $output['eshop'] = EshopMeta::toObject($object->eshop, $group); } if (($id & 1) > 0) { $output['itemGroupId'] = $object->itemGroupId; } if (($id & 2) > 0 && isset($object->itemGroupId)) { $output['itemGroupId'] = $object->itemGroupId; } if (($id & 1) > 0) { $output['itemId'] = $object->itemId; } if (($id & 2) > 0 && isset($object->itemId)) { $output['itemId'] = $object->itemId; } if (($id & 1) > 0) { $output['name'] = $object->name; } if (($id & 2) > 0 && isset($object->name)) { $output['name'] = $object->name; } if (($id & 1) > 0) { $output['longName'] = $object->longName; } if (($id & 2) > 0 && isset($object->longName)) { $output['longName'] = $object->longName; } if (($id & 1) > 0) { $output['description'] = $object->description; } if (($id & 2) > 0 && isset($object->description)) { $output['description'] = $object->description; } if (($id & 1) > 0) { $output['url'] = $object->url; } if (($id & 2) > 0 && isset($object->url)) { $output['url'] = $object->url; } if (($id & 1) > 0) { $output['price'] = $object->price; } if (($id & 2) > 0 && isset($object->price)) { $output['price'] = $object->price; } if (($id & 1) > 0) { $output['deliveryDate'] = $object->deliveryDate; } if (($id & 2) > 0 && isset($object->deliveryDate)) { $output['deliveryDate'] = $object->deliveryDate; } if (($id & 1) > 0) { if (!(isset($output['images']) && is_array($output['images']))) { $output['images'] = array(); } foreach ((array) $object->images as $k0 => $v0) { $output['images'][$k0] = ImageMeta::toObject($v0, $group); } } if (($id & 2) > 0 && isset($object->images)) { if (!(isset($output['images']) && is_array($output['images']))) { $output['images'] = array(); } foreach ((array) $object->images as $k0 => $v0) { $output['images'][$k0] = ImageMeta::toObject($v0, $group); } } if (($id & 1) > 0) { $output['ean'] = $object->ean; } if (($id & 2) > 0 && isset($object->ean)) { $output['ean'] = $object->ean; } if (($id & 1) > 0) { $output['isbn'] = $object->isbn; } if (($id & 2) > 0 && isset($object->isbn)) { $output['isbn'] = $object->isbn; } if (($id & 1) > 0) { $output['productno'] = $object->productno; } if (($id & 2) > 0 && isset($object->productno)) { $output['productno'] = $object->productno; } if (($id & 1) > 0) { $output['manufacturer'] = $object->manufacturer; } if (($id & 2) > 0 && isset($object->manufacturer)) { $output['manufacturer'] = $object->manufacturer; } if (($id & 1) > 0) { $output['brand'] = $object->brand; } if (($id & 2) > 0 && isset($object->brand)) { $output['brand'] = $object->brand; } if (($id & 1) > 0) { if (!(isset($output['categoryTexts']) && is_array($output['categoryTexts']))) { $output['categoryTexts'] = array(); } foreach ((array) $object->categoryTexts as $k0 => $v0) { $output['categoryTexts'][$k0] = $v0; } } if (($id & 2) > 0 && isset($object->categoryTexts)) { if (!(isset($output['categoryTexts']) && is_array($output['categoryTexts']))) { $output['categoryTexts'] = array(); } foreach ((array) $object->categoryTexts as $k0 => $v0) { $output['categoryTexts'][$k0] = $v0; } } if (($id & 1) > 0) { if (!(isset($output['categoryIds']) && is_array($output['categoryIds']))) { $output['categoryIds'] = array(); } foreach ((array) $object->categoryIds as $k0 => $v0) { $output['categoryIds'][$k0] = $v0; } } if (($id & 2) > 0 && isset($object->categoryIds)) { if (!(isset($output['categoryIds']) && is_array($output['categoryIds']))) { $output['categoryIds'] = array(); } foreach ((array) $object->categoryIds as $k0 => $v0) { $output['categoryIds'][$k0] = (string) $v0; } } if (($id & 1) > 0) { if (!(isset($output['categories']) && is_array($output['categories']))) { $output['categories'] = array(); } foreach ((array) $object->categories as $k0 => $v0) { $output['categories'][$k0] = CategoryMeta::toObject($v0, $group); } } if (($id & 2) > 0 && isset($object->categories)) { if (!(isset($output['categories']) && is_array($output['categories']))) { $output['categories'] = array(); } foreach ((array) $object->categories as $k0 => $v0) { $output['categories'][$k0] = CategoryMeta::toObject($v0, $group); } } if (($id & 1) > 0) { $output['itemType'] = $object->itemType; } if (($id & 2) > 0 && isset($object->itemType)) { $output['itemType'] = $object->itemType; } if (($id & 1) > 0) { if (!(isset($output['extraMessages']) && is_array($output['extraMessages']))) { $output['extraMessages'] = array(); } foreach ((array) $object->extraMessages as $k0 => $v0) { $output['extraMessages'][$k0] = $v0; } } if (($id & 2) > 0 && isset($object->extraMessages)) { if (!(isset($output['extraMessages']) && is_array($output['extraMessages']))) { $output['extraMessages'] = array(); } foreach ((array) $object->extraMessages as $k0 => $v0) { $output['extraMessages'][$k0] = $v0; } } return (object) $output; }
protected function createMeta() { return CategoryMeta::getInstance(); }
private function fillCategoryIds(Product $product) { $categoryTexts = $product->getCategoryTexts(); $categoryIds = $product->getCategoryIds(); for ($i = 0, $l = count($categoryTexts); $i < $l; ++$i) { if (isset($categoryIds[$i])) { continue; } $tree = preg_split("/\\s*[|>\\/]\\s*/", $categoryTexts[$i]); if (strncasecmp($tree[0], "heureka", 7) === 0) { array_shift($tree); } $tree = array_filter($tree, function ($name) { $name = trim($name); return !empty($name); }); if (empty($tree)) { $categoryIds[$i] = null; continue; } $hash = md5(implode(" | ", $tree)); /** @var Category $category */ $category = $this->categoryRepository->findOne([CategoryMeta::ESHOP_ID => $product->getEshopId(), CategoryMeta::HASH => $hash], ["_id" => 1]); if ($category) { $categoryIds[$i] = $category->getId(); continue; } $path = []; for ($j = 0, $m = count($tree); $j < $m; ++$j) { $treeHash = md5(implode(" | ", array_slice($tree, 0, $j + 1))); $treeCategory = new Category(); $treeCategory->setEshopId($product->getEshopId())->setHash($treeHash)->setName($tree[$j])->setPath($path); /** @var Category $savedTreeCategory */ $savedTreeCategory = $this->categoryRepository->findAndModify([CategoryMeta::ESHOP_ID => $treeCategory->getEshopId(), CategoryMeta::HASH => $treeCategory->getHash()], CategoryMeta::toArray($treeCategory), ["_id" => 1], ["upsert" => true, "new" => true]); $this->changeProducer->publish(Change::create()->setCategory($savedTreeCategory), RoutingKeys::CHANGE_CATEGORY_UPDATE); $path[$j] = $savedTreeCategory->getId(); } $categoryIds[$i] = $path[count($tree) - 1]; } $product->setCategoryIds($categoryIds); }
/** * Serializes \CC15\MQ\VO\Change to object * * @param Change $object * @param string $group * * @throws \InvalidArgumentException * * @return object */ public static function toObject($object, $group = NULL) { if ($object === null) { return null; } if (!isset(self::$groups[$group])) { throw new \InvalidArgumentException('Group \'' . $group . '\' not supported for ' . 'CC15\\MQ\\VO\\Change' . '.'); } else { $id = self::$groups[$group]; } if (!$object instanceof Change) { throw new \InvalidArgumentException('You have to pass object of class CC15\\MQ\\VO\\Change.'); } $output = array(); if (($id & 1) > 0) { $output['product'] = ProductMeta::toObject($object->product, $group); } if (($id & 2) > 0 && isset($object->product)) { $output['product'] = ProductMeta::toObject($object->product, $group); } if (($id & 1) > 0) { $output['category'] = CategoryMeta::toObject($object->category, $group); } if (($id & 2) > 0 && isset($object->category)) { $output['category'] = CategoryMeta::toObject($object->category, $group); } return (object) $output; }