public function testSingleProductFromEdited() { $ay = new \AY(53, 'h]vWu6PAuz7sfdYNZ5VqkfM^93W0k{3m'); $result = $ay->fetchProductsByIds([1966800], [ProductFields::CATEGORIES, ProductFields::VARIANTS]); $products = $result->getProducts(); $this->assertEquals(1, count($products)); $product = array_shift($products); $categories = $product->getLeafCategories(); foreach ($categories as $category) { $breadCrumb = json_encode(array_map(function ($category) { return $category->getName(); }, $category->getBreadcrumb())); } }
/** * Testing the constructor with setting the stage environment constant as api endpoint * and overwriting */ public function testConstructStageEnvironmentImageUrl() { $appId = '123'; $appPassword = '******'; $apiEndPoint = Constants::API_ENVIRONMENT_STAGE; $apiEndPointLive = Constants::API_ENVIRONMENT_LIVE; $ay = new \AY($appId, $appPassword, $apiEndPoint); /** * this assertion relies on internal implementation and relieng on live environment * urls as constant, point to refactor but actually needs a test */ $this->assertEquals($ay::IMAGE_URL_STAGE, $ay->getBaseImageUrl()); $this->assertEquals('//devcenter-staging-www1.pub.collins.kg/appjs/123.js', $ay->getJavaScriptURL()); $ayLive = new \AY($appId, $appPassword, $apiEndPointLive); $this->assertEquals('//developer.aboutyou.de/appjs/123.js', $ayLive->getJavaScriptURL()); }
/** * @param $appId * @param $cache * @return \AY */ private function getAY($appId, $cache) { $jsonString = <<<EOL [ {"facets":{"facet":[ { "name": "10", "facet_id": 126, "id": 2, "value": "10", "group_name": "size" }, { "name": "S", "facet_id": 2112, "id": 173, "value": "S", "group_name": "clothing_unisex_int" } ]}}, {"category_tree": { "parent_child": { "0": [ "74415" ] }, "ids": { "74415": { "active": true, "position": 1, "name": "Frauen", "parent": 0, "id": 74415 } } }} ] EOL; $exceptedRequestBody = '[{"facets":{}},{"category_tree":{"version":"2"}}]'; $client = $this->getGuzzleClient($jsonString, $exceptedRequestBody); $ay = new \AY($appId, 'token', Constants::API_ENVIRONMENT_LIVE, null, null, $cache); $ay->getApiClient()->setClient($client); return $ay; }
/** * {@inheritdoc} * * @return Model\VariantsResult */ public function createVariantsResult(stdClass $jsonObject) { $variants = []; $errors = []; $productSearchResult = false; foreach ($jsonObject->variant_product as $variantId => $productId) { if (!is_numeric($productId)) { $errors[] = (int) $variantId; } else { $variants[$variantId] = (int) $productId; } } $productIds = array_unique($variants); if (count($productIds) > 0) { // search products for valid variants $productSearchResult = $this->ay->fetchProductsByIds($productIds, [ProductFields::ATTRIBUTES_MERGED, ProductFields::BRAND, ProductFields::CATEGORIES, ProductFields::DEFAULT_IMAGE, ProductFields::DEFAULT_VARIANT, ProductFields::DESCRIPTION_LONG, ProductFields::DESCRIPTION_SHORT, ProductFields::IS_ACTIVE, ProductFields::IS_SALE, ProductFields::MAX_PRICE, ProductFields::MIN_PRICE, ProductFields::VARIANTS, ProductFields::INACTIVE_VARIANTS]); } return Model\VariantsResult::create($variants, $errors, $productSearchResult); }
public function testFromJson() { $jsonObject = $this->getJsonObject('image.json'); $image = Image::createFromJson($jsonObject); $this->assertNotNull($image->getBaseUrl()); $this->assertEquals('hash1', $image->getHash()); $this->assertEquals('.jpg', $image->getExt()); $this->assertEquals('image/jpeg', $image->getMimetype()); $this->assertEquals(12345678, $image->getFilesize()); $this->assertEquals(array('tag1', 'tag2'), $image->getTags()); $imageSize = $image->getImageSize(); $this->assertInstanceOf('\\AboutYou\\SDK\\Model\\ImageSize', $imageSize); $this->assertEquals(1400, $imageSize->getWidth()); $this->assertEquals(2000, $imageSize->getHeight()); $image->setBaseUrl(); $this->assertStringStartsWith('/hash1', $image->getUrl()); $image->setBaseUrl(false); $this->assertStringStartsWith('/hash1', $image->getUrl()); $image->setBaseUrl(null); $this->assertStringStartsWith('/hash1', $image->getUrl()); $image->setBaseUrl(''); $this->assertStringStartsWith('/hash1', $image->getUrl()); $this->assertStringStartsWith('/hash1?width=123&height=456', $image->getUrl(123, 456)); $ay = new \AY('appid', 'pw'); $ay->getResultFactory(); $this->assertStringStartsWith(\AY::IMAGE_URL_LIVE . '/hash1', $image->getUrl()); $ay->setBaseImageUrl('http://domain.tld'); $this->assertStringStartsWith('http://domain.tld/hash1', $image->getUrl()); $ay->setBaseImageUrl(false); $this->assertStringStartsWith('/hash1', $image->getUrl()); $ay->setBaseImageUrl(null); $this->assertStringStartsWith(\AY::IMAGE_URL_LIVE . '/hash1', $image->getUrl()); $ay->getResultFactory()->setBaseImageUrl('http://domain2.tld'); $this->assertStringStartsWith('http://domain2.tld/hash1', $image->getUrl()); Image::setBaseUrl('http://domain3.tld'); $this->assertStringStartsWith('http://domain3.tld/hash1', $image->getUrl()); $this->assertNull($image->getAdditionalItems()); $this->assertNull($image->getAngle()); $this->assertNull($image->getBackground()); $this->assertNull($image->getColor()); $this->assertNull($image->getFocus()); $this->assertNull($image->getGender()); $this->assertNull($image->getModelData()); $this->assertNull($image->getNextDetailLevel()); $this->assertNull($image->getPreparation()); $this->assertNull($image->getView()); $this->assertNull($image->getType()); }
/** * @return \AboutYou\SDK\Factory\ModelFactoryInterface */ protected function getModelFactory() { $ay = new \AY('id', 'token'); return $ay->getResultFactory(); }
/** * @param string|string[] $jsonString * @param string $exceptedRequestBody * * @return \AY */ protected function getAYWithResult($jsonString, $exceptedRequestBody = null) { $client = $this->getGuzzleClient($jsonString, $exceptedRequestBody); $ay = new \AY('100', 'token'); $ay->getApiClient()->setClient($client); if ($this->setupCategoryManager === true) { $this->setupCategoryManager($ay); } if ($this->facetsResultPath) { $facets = $this->getFacetList($this->facetsResultPath); $ay->getResultFactory()->getFacetManager()->setFacets($facets); } return $ay; }
/** * @param null|false|string $devCenterApiURL null will reset to the default url, false to get relative urls, otherwise the url prefix */ public static function setDevCenterApiUrl($devcenterApiUrl = null) { // if DevCenter API URL endpoint already set, don't overwrite it with // empty or null if (self::$devcenterApiUrl && !$devcenterApiUrl) { return; } if ($devcenterApiUrl === null) { self::$devcenterApiUrl = self::DEVCENTER_API_URL_LIVE; } else { if (is_string($devcenterApiUrl)) { self::$devcenterApiUrl = rtrim($devcenterApiUrl, '/'); } else { self::$devcenterApiUrl = ''; } } }
public function getProduct($filename) { $json = $this->getJsonObjectFromFile('product/' . $filename); $product = Product::createFromJson($json, $this->ay->getResultFactory(), 98); return $product; }