本文整理汇总了PHP中Mage_Catalog_Model_Product::getMediaGalleryImages方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getMediaGalleryImages方法的具体用法?PHP Mage_Catalog_Model_Product::getMediaGalleryImages怎么用?PHP Mage_Catalog_Model_Product::getMediaGalleryImages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getMediaGalleryImages方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getItemImages
public function getItemImages()
{
$this->item['item_imgs'] = array();
$name = basename($this->product->getImageUrl());
if ($images = $this->product->getMediaGalleryImages()) {
if (count($images) > 0) {
$position = 0;
foreach ($images as $image) {
$itemImg = array();
$itemImg['img_id'] = $image->getId();
$itemImg['img_url'] = $this->getItemImageUrl($image->getFile());
$itemImg['position'] = ++$position;
if ($position > 1 && $name == basename($image->getFile())) {
$first = $itemImg;
$first['position'] = 0;
} else {
$this->item['item_imgs'][] = $itemImg;
}
}
if (isset($first)) {
$this->item['item_imgs'] = array_merge(array($first), $this->item['item_imgs']);
}
return $this->item['item_imgs'];
}
}
$itemImg = array();
$itemImg['img_id'] = 0;
$itemImg['img_url'] = $this->getItemImageUrl();
$itemImg['position'] = 0;
$this->item['item_imgs'][] = $itemImg;
return $this->item['item_imgs'];
}
示例2: _getProductImageFile
protected function _getProductImageFile()
{
$product = new Mage_Catalog_Model_Product();
$product->load(1);
$images = $product->getMediaGalleryImages()->getItems();
$image = reset($images);
return $image['file'];
}
示例3: _getImageFromGallery
/**
* Get the first image from the image gallery.
*
* @param Mage_Catalog_Model_Product $product
*
* @return string
*/
private function _getImageFromGallery(Mage_Catalog_Model_Product $product)
{
$gallery = $product->getMediaGalleryImages();
if (!$gallery->count()) {
return '';
}
$image = $gallery->getFirstItem();
if (!$image || !$image->hasFile()) {
return '';
}
return $image->getFile();
}
示例4: _getGalleryImageItems
/**
* @param Mage_Catalog_Model_Product $product
* @return array
*/
protected function _getGalleryImageItems(Mage_Catalog_Model_Product $product)
{
try {
$galleryImagesCollection = $product->getMediaGalleryImages();
} catch (Exception $e) {
// Do nothing here under the assumption that this product has no gallery images
return array();
}
if (!is_object($galleryImagesCollection) || $galleryImagesCollection->count() < 1) {
return array();
}
return $galleryImagesCollection->getItems();
}
示例5: testGetMediaGalleryImages
public function testGetMediaGalleryImages()
{
/** @var $model Mage_Catalog_Model_Product */
$model = Mage::getModel('Mage_Catalog_Model_Product');
$this->assertEmpty($model->getMediaGalleryImages());
$this->_model->setMediaGallery(array('images' => array(array('file' => 'magento_image.jpg'))));
$images = $this->_model->getMediaGalleryImages();
$this->assertInstanceOf('Varien_Data_Collection', $images);
foreach ($images as $image) {
$this->assertInstanceOf('Varien_Object', $image);
$image = $image->getData();
$this->assertArrayHasKey('file', $image);
$this->assertArrayHasKey('url', $image);
$this->assertArrayHasKey('id', $image);
$this->assertArrayHasKey('path', $image);
$this->assertStringEndsWith('magento_image.jpg', $image['file']);
$this->assertStringEndsWith('magento_image.jpg', $image['url']);
$this->assertStringEndsWith('magento_image.jpg', $image['path']);
}
}
示例6: getAltImgHtml
/**
* Get alternative image HTML of the given product
*
* @param Mage_Catalog_Model_Product $product Product
* @param int $w Image width
* @param int $h Image height
* @param string $imgVersion Image version: image, small_image, thumbnail
* @return string
*/
public function getAltImgHtml($product, $w, $h, $imgVersion = 'small_image')
{
$column = $this->getCfg('category/alt_image_column');
$value = $this->getCfg('category/alt_image_column_value');
$product->load('media_gallery');
if ($gal = $product->getMediaGalleryImages()) {
if ($altImg = $gal->getItemByColumnValue($column, $value)) {
return '<img class="alt-img" src="' . Mage::helper('infortis/image')->getImg($product, $w, $h, $imgVersion, $altImg->getFile()) . '" alt="' . $product->getName() . '" />';
}
}
return '';
}
示例7: getAltImgHtml
/**
* Get alternative image HTML of the given product
*
* @param Mage_Catalog_Model_Product $product Product
* @param int $w Image width
* @param int $h Image height
* @param string $imgVersion Image version: image, small_image, thumbnail
* @return string
*/
public function getAltImgHtml($product, $w, $h, $imgVersion = 'small_image')
{
$column = $this->getConfig('category_product/alt_image_column');
$value = $this->getConfig('category_product/alt_image_column_value');
$product->load('media_gallery');
if ($gal = $product->getMediaGalleryImages()) {
$altImg = $gal->getItemByColumnValue($column, $value);
if (!$altImg) {
$altImg = $gal->getItemByColumnValue('position', 1);
}
if (isset($altImg) && $altImg->getFile()) {
return Mage::helper('themesettings/image')->getImg($product, $w, $h, $imgVersion, $altImg->getFile());
} else {
return '';
}
}
return '';
}
示例8: _extractImageData
/**
* extracting image data from a given Mage_Catalog_Model_Product object
* @param Mage_Catalog_Model_Product $product
* @return array | null
*/
protected function _extractImageData(Mage_Catalog_Model_Product $product)
{
$media = $product->getMediaGalleryImages();
return $media && $media->count() ? ['id' => $product->getSku(), 'image_data' => $this->_getMediaData($media, $product)] : null;
}
示例9: _createImageUrls
/**
* Returns data about images associated with product
* @param Mage_Catalog_Model_Product $product
* @return array|null
*/
protected function _createImageUrls(Mage_Catalog_Model_Product $product)
{
$result = array();
//get media images associated with product
$images = $product->getMediaGalleryImages();
if (!empty($images)) {
foreach ($images as $image) {
$isDeleted = $image->getRemoved();
if (!$isDeleted) {
$label = $image->getLabel();
$data = array('url' => $this->_getNotSecureImageUrl($image->getUrl()), 'height' => null, 'width' => null, 'label' => $label ? $this->_createLocalizedValue($label) : null, 'altText' => null, 'tags' => null);
$result[] = $data;
}
}
}
$image = $product->getData('image');
if (!empty($image) && $image != 'no_selection') {
$imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image');
$label = $product->getData('image_label');
$data = array('url' => $this->_getNotSecureImageUrl($imageUrl), 'height' => null, 'width' => null, 'label' => $label ? $this->_createLocalizedValue($label) : null, 'altText' => null, 'tags' => null);
$result[] = $data;
}
$image = $product->getData('small_image');
if (!empty($image) && $image != 'no_selection') {
$imageUrl = (string) Mage::helper('catalog/image')->init($product, 'small_image');
$label = $product->getData('small_image_label');
$data = array('url' => $this->_getNotSecureImageUrl($imageUrl), 'height' => null, 'width' => null, 'label' => $label ? $this->_createLocalizedValue($label) : null, 'altText' => null, 'tags' => null);
$result[] = $data;
}
$image = $product->getData('thumbnail');
if (!empty($image) && $image != 'no_selection') {
$imageUrl = (string) Mage::helper('catalog/image')->init($product, 'thumbnail');
$label = $product->getData('thumbnail_label');
$data = array('url' => $this->_getNotSecureImageUrl($imageUrl), 'height' => null, 'width' => null, 'label' => $label ? $this->_createLocalizedValue($label) : null, 'altText' => null, 'tags' => array('THUMBNAIL'));
$result[] = $data;
}
return count($result) ? $result : null;
}
示例10: getObject
public function getObject(Mage_Catalog_Model_Product $product)
{
$this->logger->start('CREATE RECORD ' . $product->getId() . ' ' . $this->logger->getStoreName($product->storeId));
$this->logger->log('Product type (' . $product->getTypeId() . ')');
$defaultData = array();
$transport = new Varien_Object($defaultData);
Mage::dispatchEvent('algolia_product_index_before', array('product' => $product, 'custom_data' => $transport));
$defaultData = $transport->getData();
$defaultData = is_array($defaultData) ? $defaultData : explode("|", $defaultData);
$customData = array('objectID' => $product->getId(), 'name' => $product->getName(), 'url' => $product->getProductUrl());
$additionalAttributes = $this->config->getProductAdditionalAttributes($product->getStoreId());
$groups = null;
if ($this->isAttributeEnabled($additionalAttributes, 'description')) {
$customData['description'] = $product->getDescription();
}
$categories = array();
$categories_with_path = array();
$_categoryIds = $product->getCategoryIds();
if (is_array($_categoryIds) && count($_categoryIds) > 0) {
$categoryCollection = Mage::getResourceModel('catalog/category_collection')->addAttributeToSelect('name')->addAttributeToFilter('entity_id', $_categoryIds)->addIsActiveFilter();
foreach ($categoryCollection as $category) {
$categoryName = $category->getName();
if ($categoryName) {
$categories[] = $categoryName;
}
$category->getUrlInstance()->setStore($product->getStoreId());
$path = array();
foreach ($category->getPathIds() as $treeCategoryId) {
$name = $this->getCategoryName($treeCategoryId, $product->getStoreId());
if ($name) {
$path[] = $name;
}
}
$categories_with_path[] = $path;
}
}
foreach ($categories_with_path as $result) {
for ($i = count($result) - 1; $i > 0; $i--) {
$categories_with_path[] = array_slice($result, 0, $i);
}
}
$categories_with_path = array_intersect_key($categories_with_path, array_unique(array_map('serialize', $categories_with_path)));
$categories_hierarchical = array();
$level_name = 'level';
foreach ($categories_with_path as $category) {
for ($i = 0; $i < count($category); $i++) {
if (isset($categories_hierarchical[$level_name . $i]) === false) {
$categories_hierarchical[$level_name . $i] = array();
}
$categories_hierarchical[$level_name . $i][] = implode(' /// ', array_slice($category, 0, $i + 1));
}
}
foreach ($categories_hierarchical as &$level) {
$level = array_values(array_unique($level));
}
foreach ($categories_with_path as &$category) {
$category = implode(' /// ', $category);
}
$customData['categories'] = $categories_hierarchical;
$customData['categories_without_path'] = $categories;
if (false === isset($defaultData['thumbnail_url'])) {
try {
$customData['thumbnail_url'] = $product->getThumbnailUrl();
$customData['thumbnail_url'] = str_replace(array('https://', 'http://'), '//', $customData['thumbnail_url']);
} catch (\Exception $e) {
}
}
if (false === isset($defaultData['image_url'])) {
try {
$customData['image_url'] = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getImage());
$customData['image_url'] = str_replace(array('https://', 'http://'), '//', $customData['image_url']);
} catch (\Exception $e) {
}
if ($this->isAttributeEnabled($additionalAttributes, 'media_gallery')) {
$product->load('media_gallery');
$customData['media_gallery'] = array();
foreach ($product->getMediaGalleryImages() as $image) {
$customData['media_gallery'][] = str_replace(array('https://', 'http://'), '//', $image->getUrl());
}
}
}
$sub_products = null;
$ids = null;
if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle') {
if ($product->getTypeId() == 'bundle') {
$ids = array();
$selection = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
foreach ($selection as $option) {
$ids[] = $option->product_id;
}
}
if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'grouped') {
$ids = $product->getTypeInstance(true)->getChildrenIds($product->getId());
}
if (count($ids)) {
$sub_products = $this->getProductCollectionQuery($product->getStoreId(), $ids, false)->load();
} else {
$sub_products = array();
}
}
//.........这里部分代码省略.........