1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_XmlConnect_Block_Catalog_Product_Gallery extends Mage_XmlConnect_Block_Catalog
35: {
36: 37: 38: 39: 40:
41: protected function _toHtml()
42: {
43: $productId = $this->getRequest()->getParam('id', null);
44: $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId);
45: $collection = $product->getMediaGalleryImages();
46:
47: $imagesNode = Mage::getModel('xmlconnect/simplexml_element', '<images></images>');
48: $helper = $this->helper('catalog/image');
49:
50: foreach ($collection as $item) {
51: $imageNode = $imagesNode->addChild('image');
52:
53: 54: 55:
56: $bigImage = $helper->init($product, 'image', $item->getFile())->constrainOnly(true)->keepFrame(false)
57: ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_gallery_big'));
58:
59: $fileNode = $imageNode->addChild('file');
60: $fileNode->addAttribute('type', 'big');
61: $fileNode->addAttribute('url', $bigImage);
62:
63: $file = Mage::helper('xmlconnect')->urlToPath($bigImage);
64:
65: $fileNode->addAttribute('id', ($id = $item->getId()) ? (int) $id : 0);
66: $fileNode->addAttribute('modification_time', filemtime($file));
67:
68: 69: 70:
71: $smallImage = $helper->init($product, 'thumbnail', $item->getFile())->constrainOnly(true)->keepFrame(false)
72: ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_gallery_small'));
73:
74: $fileNode = $imageNode->addChild('file');
75: $fileNode->addAttribute('type', 'small');
76: $fileNode->addAttribute('url', $smallImage);
77:
78: $file = Mage::helper('xmlconnect')->urlToPath($smallImage);
79: $fileNode->addAttribute('modification_time', filemtime($file));
80: }
81: return $imagesNode->asNiceXml();
82: }
83: }
84: