/**
  * @return \Generated\Shared\Transfer\ElasticsearchIndexDefinitionTransfer[]
  */
 public function loadIndexDefinitions()
 {
     $indexDefinitions = [];
     $jsonFiles = $this->getJsonFiles();
     foreach ($jsonFiles as $jsonFile) {
         $definitionData = Json::decode($jsonFile->getContents(), true);
         $indexDefinitions = $this->getDefinitionByStores($jsonFile, $indexDefinitions, $definitionData);
     }
     return $this->createIndexDefinitions($indexDefinitions);
 }
Example #2
0
 /**
  * @throws \Spryker\Zed\Application\Business\Exception\NavigationCacheFileDoesNotExistException
  * @throws \Spryker\Zed\Application\Business\Exception\NavigationCacheEmptyException
  *
  * @return array
  */
 public function getNavigation()
 {
     if (!file_exists($this->cacheFile)) {
         throw new NavigationCacheFileDoesNotExistException('Navigation cache is enabled, but there is no cache file.');
     }
     $content = file_get_contents($this->cacheFile);
     if (empty($content)) {
         throw new NavigationCacheEmptyException('Navigation cache is enabled, but cache is empty.');
     }
     return Json::decode($content, true);
 }
 /**
  * @param string $body
  *
  * @return array
  */
 protected function prepareBody($body)
 {
     if ($this->isJson($body)) {
         $body = Json::decode($body, true);
     }
     if (is_array($body)) {
         $body = $this->sanitizer->sanitize($body);
     }
     if (is_string($body)) {
         $body = ['transfer-response' => $body];
     }
     $body = $this->prepareValues($body);
     return $body;
 }
Example #4
0
 /**
  * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
  *
  * @return array
  */
 protected function prepareData(TableConfiguration $config)
 {
     $query = $this->productCategoryQueryContainer->queryProductsAbstractBySearchTerm(null, $this->locale);
     $query->setModelAlias('spy_product_abstract');
     $queryResults = $this->runQuery($query, $config);
     $results = [];
     foreach ($queryResults as $product) {
         $info = ['id' => $product[SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT], 'sku' => $product[SpyProductAbstractTableMap::COL_SKU], 'name' => urlencode($product['name'])];
         $checkbox_html = sprintf("<input id='all_products_checkbox_%d' class='all-products-checkbox' type='checkbox' data-info='%s'>", $product[SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT], Json::encode($info));
         $results[] = [SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT => $product[SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT], SpyProductAbstractTableMap::COL_SKU => $product[SpyProductAbstractTableMap::COL_SKU], SpyProductAbstractLocalizedAttributesTableMap::COL_NAME => $product['name'], self::COL_CHECKBOX => $checkbox_html];
     }
     unset($queryResults);
     return $results;
 }
Example #5
0
 /**
  * @param string $serialized
  *
  * @throws \Spryker\Shared\Transfer\Exception\TransferUnserializationException
  *
  * @return void
  */
 public function unserialize($serialized)
 {
     try {
         $this->fromArray(Json::decode($serialized, true), true);
         $this->initCollectionProperties();
     } catch (Exception $exception) {
         throw new TransferUnserializationException(sprintf('Failed to unserialize %s. Updating or clearing your data source may solve this problem: %s', get_class($this), $exception->getMessage()), $exception->getCode(), $exception);
     }
 }
 /**
  * @param \Orm\Zed\Product\Persistence\SpyProductAbstract $abstractProductEntity
  * @param \Orm\Zed\Product\Persistence\SpyProductAbstractLocalizedAttributes $localizedAttributeEntity
  * @param array $abstractProductAttributes
  *
  * @return \Generated\Shared\Transfer\ProductVariantTransfer
  */
 protected function hydrateAbstractProductVariant(SpyProductAbstract $abstractProductEntity, SpyProductAbstractLocalizedAttributes $localizedAttributeEntity, array $abstractProductAttributes)
 {
     $productVariantTransfer = new ProductVariantTransfer();
     $abstractProduct = $abstractProductEntity->toArray();
     unset($abstractProduct['attributes']);
     $productVariantTransfer->fromArray($abstractProduct, true);
     $localizedAttributes = $localizedAttributeEntity->toArray();
     unset($localizedAttributes['attributes']);
     $productVariantTransfer->fromArray($localizedAttributes, true);
     $productVariantTransfer->setLocaleName($localizedAttributeEntity->getLocale()->getLocaleName());
     $localizedAttributes = array_merge($abstractProductAttributes, Json::decode($localizedAttributeEntity->getAttributes(), true));
     $productVariantTransfer->setAttributes($localizedAttributes);
     return $productVariantTransfer;
 }
Example #7
0
 /**
  * @param mixed $expected
  * @param string $given
  *
  * @dataProvider dataProvider
  *
  * @return void
  */
 public function testDecode($expected, $given)
 {
     $this->assertEquals($expected, Json::decode($given, true));
 }
 /**
  * @param array $productCategory
  *
  * @return string
  */
 protected function getOrderHtml(array $productCategory)
 {
     $info = ['id' => $productCategory['id_product_abstract']];
     return sprintf("<input type='text' value='%d' id='product_category_order_%d' class='product_category_order' size='4' data-info='%s'>", $productCategory['product_order'], $productCategory['id_product_abstract'], Json::encode($info));
 }
 /**
  * Checks, that JSON serialization is used in the cache.
  *
  * @return void
  */
 public function testCacheShouldNotUseSerialize()
 {
     $cacheFile = $this->getCacheFile();
     $isEnabled = true;
     $navigationCache = new NavigationCache($cacheFile, $isEnabled);
     $navigationData = ['foo' => 'bar'];
     $navigationCache->setNavigation($navigationData);
     $rawData = file_get_contents($cacheFile);
     $this->assertEquals($navigationData, Json::decode($rawData, true));
     $this->assertEquals($rawData, Json::encode($navigationData));
 }
 /**
  * @return string
  */
 protected function convertToJson()
 {
     $config = ['propel' => $this->config];
     return Json::encode($config);
 }