diff --git a/readme.md b/readme.md index e7be570..cf5e94f 100755 --- a/readme.md +++ b/readme.md @@ -60,6 +60,17 @@ $icecat->getImages(5); // Returns key => value array with specifications. e.g: ['cpu' => 'Core I5', 'screensize' => '15.6'] $icecat->getSpecs(); + +// Returns array with videos of the product. +$icecat->getVideos(); + +// Returns array with manuals. +$icecat->getManuals(); + +// Returns array with 360 images. +$icecat->get360imageArray(); + + ``` Demo is soon available. diff --git a/src/Model/Result.php b/src/Model/Result.php index 22898c9..89ffda1 100755 --- a/src/Model/Result.php +++ b/src/Model/Result.php @@ -21,7 +21,7 @@ class Result implements ResultInterface * @var array */ private $images = []; - + /** * The multimedia objects as an array. * @@ -29,6 +29,7 @@ class Result implements ResultInterface */ private $multimediaObjects = []; + /** * Icecat Constructor. * @@ -180,13 +181,15 @@ private function productHasMainImage() { return !empty($this->getProductData()->{'@attributes'}->HighPic); } - + /** - * Gets an array of images. + * Gets an array of multimedia Objects. + * + * @param string $objectType MultimediaObjectType (video/mp4|manual|360|leaflet) * * @return array */ - public function getMultimediaObjects() + public function getMultimediaObjects($objectType = '') { if (empty($this->multimediaObjects)) { if ($this->productHasMultimediaObject()) { @@ -195,24 +198,68 @@ public function getMultimediaObjects() if (!is_array($productMultimediaObjects)){ $productMultimediaObjects = [$productMultimediaObjects]; } - - foreach ($productMultimediaObjects as $multimediaObject) { - $attr = $multimediaObject->{'@attributes'}; - $this->multimediaObjects[] = [ + foreach ($productMultimediaObjects as $productMultimediaObject) { + $attr = $productMultimediaObject->{'@attributes'}; + $multimediaObject = [ 'contentType' => $attr->ContentType, 'description' => $attr->Description, - 'size' => $attr->Size, - 'type' => $attr->Type, - 'url' => $attr->URL, - 'langId' => $attr->langid, - ]; + 'size' => (!empty($attr->Size) ? $attr->Size : 0), + 'url' => (!empty($attr->URL) ? $attr->URL : ''), + ]; + + // retrieve 360 images? + if ($attr->Type == '360') { + $images360 = []; + + foreach ($productMultimediaObject->ImagesList360->Image as $image) { + $attr = $image->{'@attributes'}; + $images360[(int) $attr->No] = $attr->Link; + } + $multimediaObject['image360'] = $images360; + } + + $this->multimediaObjects[$attr->Type][] = $multimediaObject; } } } - - return $this->multimediaObjects; + + if (empty($objectType)) { + return $this->multimediaObjects; + } + + return (isset($this->multimediaObjects[$objectType]) ? $this->multimediaObjects[$objectType] : []); + } + + /** + * Gets an array of 360 images. + * + * @return array + */ + public function get360imageArray() + { + return $this->getMultimediaObjects('360'); } + /** + * Gets an array of manuals. + * + * @return array + */ + public function getManuals() + { + return $this->getMultimediaObjects('manual'); + } + + /** + * Gets an array of videos. + * + * @return array + */ + public function getVideos() + { + return $this->getMultimediaObjects('video/mp4'); + } + /** * Checks if the product has multimedia objects. * @@ -222,7 +269,7 @@ private function productHasMultimediaObject() { return !empty($this->getProductData()->ProductMultimediaObject->MultimediaObject); } - + /** * Checks if the product has Product Features. * @@ -246,7 +293,7 @@ public function getSpecByIdentifier($identifier) { if ($this->productHasProductFeature()) { $productFeature = $this->getProductData()->ProductFeature; - + // Make sure $productFeature is an array. if (!is_array($productFeature)) { $productFeature = [$productFeature]; @@ -272,7 +319,7 @@ public function getSpecByName($specificationName) { if ($this->productHasProductFeature()) { $productFeature = $this->getProductData()->ProductFeature; - + // Make sure $productFeature is an array. if (!is_array($productFeature)) { $productFeature = [$productFeature]; @@ -294,10 +341,10 @@ public function getSpecByName($specificationName) public function getSpecs() { $specifications = []; - + if ($this->productHasProductFeature()) { $productFeature = $this->getProductData()->ProductFeature; - + // Make sure $productFeature is an array. if (!is_array($productFeature)) { $productFeature = [$productFeature];