protected function _afterToHtml($html) { $imageSize = Mage::helper('swatches')->getthumbImageSize(); $html = parent::_afterToHtml($html); if ('product.info.options.configurable' == $this->getNameInLayout()) { $html = str_replace('super-attribute-select', 'no-display super-attribute-select', $html); $simpleProducts = $this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct()); if ($this->_optionProducts) { $this->_optionProducts = array_values($this->_optionProducts); foreach ($simpleProducts as $simple) { $key = array(); for ($i = 0; $i < count($this->_optionProducts); $i++) { foreach ($this->_optionProducts[$i] as $optionId => $productIds) { if (in_array($simple->getId(), $productIds)) { $key[] = $optionId; } } } if ($key) { $strKey = implode(',', $key); $confData[$strKey] = array(); $confData[$strKey]['parent_image'] = (string) $this->helper('catalog/image')->init($this->getProduct(), 'small_image')->resize($imageSize); $confData[$strKey]['small_image'] = (string) $this->helper('catalog/image')->init($simple, 'small_image')->resize($imageSize); } } $html .= '<script type="text/javascript"> confData[' . $this->getProduct()->getEntityId() . '] = new swatchesListingData(' . Zend_Json::encode($confData) . '); </script>'; } } return $html; }
protected function _afterToHtml($html) { $attributeIdsWithImages = Mage::registry('swatches_allowed_ids'); $confData = array(); $html = parent::_afterToHtml($html); if ('product.info.options.configurable' == $this->getNameInLayout() && Mage::getStoreConfig('swatches/default/show_swatches')) { if (!empty($attributeIdsWithImages)) { foreach ($attributeIdsWithImages as $attrIdToHide) { $html = preg_replace('@(id="attribute' . $attrIdToHide . ')(-)?([0-9]*)(")(\\s+)(class=")(.*?)(super-attribute-select)(-)?([0-9]*)@', '$1$2$3$4$5$6$7$8$9$10 no-display', $html); } } $simpleProducts = $this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct()); if ($this->childProducts) { $this->childProducts = array_values($this->childProducts); foreach ($simpleProducts as $simple) { $key = array(); for ($i = 0; $i < count($this->childProducts); $i++) { foreach ($this->childProducts[$i] as $optionId => $productIds) { if (in_array($simple->getId(), $productIds)) { $key[] = $optionId; } } } if ($key) { $strKey = implode(',', $key); if ($simple->getImage()) { $imgGallery = Mage::getModel('catalog/product')->load($simple->getId())->getMediaGalleryImages(); $i = 0; if ($simple->getImage() == 'no_selection') { $confData[$strKey]['media_url'][$i]['label'] = $simple->getImageLabel(); $confData[$strKey]['media_url'][$i]['url'] = $this->getSkinUrl('images/catalog/product/placeholder/image.jpg'); $confData[$strKey]['media_url'][$i]['galleryUrl'] = $this->getSkinUrl('images/catalog/product/placeholder/image.jpg'); } else { $confData[$strKey]['media_url'][$i]['label'] = $simple->getImageLabel(); $confData[$strKey]['media_url'][$i]['url'] = Mage::helper('catalog/output')->productAttribute($simple, Mage::helper('catalog/image')->init($simple, 'image')->resize(265), 'image')->__toString(); $confData[$strKey]['media_url'][$i]['galleryUrl'] = Mage::helper('catalog/image')->init($simple, 'image'); } if (count($imgGallery) > 0) { foreach ($imgGallery as $_image) { ++$i; $params = array('id' => $simple->getId(), 'image' => $_image->getValueId()); $galleryUrl = $this->getUrl('catalog/product/gallery', $params); $confData[$strKey]['media_url'][$i]['label'] = $_image->getLabel(); $confData[$strKey]['media_url'][$i]['url'] = $_image->getUrl(); $confData[$strKey]['media_url'][$i]['galleryUrl'] = $galleryUrl; } } else { $confData[$strKey]['media_url'][1]['label'] = ''; $confData[$strKey]['media_url'][1]['url'] = ''; $confData[$strKey]['media_url'][1]['galleryUrl'] = ''; } } } } $html .= '<script type="text/javascript"> additionalData = new PDPSwatchesData(' . Zend_Json::encode($confData) . '); </script>'; } } return $html; }
protected function _afterToHtml($html) { $imageSizeAtCategoryPage = Mage::getStoreConfig('amconf/list/main_image_list_size'); $html = parent::_afterToHtml($html); if ('product.info.options.configurable' == $this->getNameInLayout()) { $html = str_replace('super-attribute-select', 'no-display super-attribute-select', $html); // both config setting and product attribute should be set to "Yes" $_useSimplePrice = (Mage::helper('amconf')->getConfigUseSimplePrice() and $this->getProduct()->getData('amconf_simple_price')) ? true : false; $simpleProducts = $this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct()); if ($this->_optionProducts) { $noimgUrl = Mage::helper('amconf')->getNoimgImgUrl(); $this->_optionProducts = array_values($this->_optionProducts); foreach ($simpleProducts as $simple) { /* @var $simple Mage_Catalog_Model_Product */ $key = array(); for ($i = 0; $i < count($this->_optionProducts); $i++) { foreach ($this->_optionProducts[$i] as $optionId => $productIds) { if (in_array($simple->getId(), $productIds)) { $key[] = $optionId; } } } if ($key) { $strKey = implode(',', $key); // @todo check settings: // array key here is a combination of choosen options $confData[$strKey] = array(); if (!('no_selection' == $simple->getSmallImage() || '' == $simple->getSmallImage())) { $confData[$strKey]['small_image'] = (string) $this->helper('catalog/image')->init($simple, 'small_image')->resize($imageSizeAtCategoryPage); $confData[$strKey]['parent_image'] = (string) $this->helper('catalog/image')->init($this->getProduct(), 'small_image')->resize($imageSizeAtCategoryPage); if (Mage::getStoreConfig('amconf/general/oneselect_reload')) { $k = $strKey; if (strpos($strKey, ',') > 0) { $k = substr($strKey, 0, strpos($strKey, ',')); } if (!(array_key_exists($k, $confData) && array_key_exists('small_image', $confData[$k]))) { $confData[$k]['small_image'] = $confData[$strKey]['small_image']; $confData[$k]['parent_image'] = $confData[$strKey]['parent_image']; } } else { //for only first } } else { $confData[$strKey]['small_image'] = (string) $this->helper('catalog/image')->init($this->getProduct(), 'small_image')->resize($imageSizeAtCategoryPage); $confData[$strKey]['parent_image'] = (string) $this->helper('catalog/image')->init($this->getProduct(), 'small_image')->resize($imageSizeAtCategoryPage); } if (Mage::getStoreConfig('amconf/general/reload_name')) { $confData[$strKey]['name'] = $simple->getName(); } // the html blocks are required for product view page if ($_useSimplePrice) { $tierPriceHtml = $this->getTierPriceHtml($simple); $confData[$strKey]['price_html'] = $this->getPriceHtml($simple) . $tierPriceHtml; $confData[$strKey]['price_clone_html'] = $this->getPriceHtml($simple, false, '_clone') . $tierPriceHtml; } //for >3 if (Mage::getStoreConfig('amconf/general/oneselect_reload')) { $pos = strpos($strKey, ","); if ($pos) { $pos = strpos($strKey, ",", $pos + 1); if ($pos) { $newKey = substr($strKey, 0, $pos); $confData[$newKey] = $confData[$strKey]; } } } } } $html = '<script type="text/javascript"> confData[' . $this->getProduct()->getEntityId() . '] = new AmConfigurableData(' . Zend_Json::encode($confData) . '); confData[' . $this->getProduct()->getEntityId() . '].textNotAvailable = "' . $this->__('Choose previous option please...') . '"; confData[' . $this->getProduct()->getEntityId() . '].oneAttributeReload = "' . (bool) Mage::getStoreConfig('amconf/general/oneselect_reload') . '"; confData[' . $this->getProduct()->getEntityId() . '].useSimplePrice = "' . intval($_useSimplePrice) . '"; amRequaredField = "' . $this->__('↑ This is a required field.') . '"; </script>' . $html; } } return $html; }
protected function _afterToHtml($html) { $attributeIdsWithImages = Mage::registry('amconf_images_attrids'); $html = parent::_afterToHtml($html); if ('product.info.options.configurable' == $this->getNameInLayout()) { if (Mage::getStoreConfig('amconf/general/hide_dropdowns')) { if (!empty($attributeIdsWithImages)) { foreach ($attributeIdsWithImages as $attrIdToHide) { $html = preg_replace('@(id="attribute' . $attrIdToHide . ')(-)?([0-9]*)(")(\\s+)(class=")(.*?)(super-attribute-select)(-)?([0-9]*)@', '$1$2$3$4$5$6$7$8$9$10 no-display', $html); } } } $_useSimplePrice = Mage::helper('amconf')->getConfigUseSimplePrice() == 2 || (Mage::helper('amconf')->getConfigUseSimplePrice() == 1 and $this->getProduct()->getData('amconf_simple_price')) ? true : false; $simpleProducts = $this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct()); if ($this->_currentAttributes) { $this->_currentAttributes = array_unique($this->_currentAttributes); $noimgUrl = Mage::helper('amconf')->getNoimgImgUrl(); $reloadValues = explode(',', Mage::getStoreConfig('amconf/general/reload_content')); foreach ($simpleProducts as $simple) { if (version_compare(Mage::getVersion(), '1.9.1.0', '>=')) { $simple = Mage::getModel('catalog/product')->load($simple->getId()); } /* @var $simple Mage_Catalog_Model_Product */ $key = array(); foreach ($this->_currentAttributes as $attributeCode) { $key[] = $simple->getData($attributeCode); } if ($key) { $strKey = implode(',', $key); // @todo check settings: // array key here is a combination of choosen options $confData[$strKey] = array(); if (in_array('name', $reloadValues)) { $confData[$strKey]['name'] = $simple->getName(); } if (in_array('short_description', $reloadValues)) { $confData[$strKey]['short_description'] = $this->helper('catalog/output')->productAttribute($simple, nl2br($simple->getShortDescription()), 'short_description'); } if (in_array('description', $reloadValues)) { $confData[$strKey]['description'] = $this->helper('catalog/output')->productAttribute($simple, $simple->getDescription(), 'description'); } if (in_array('attributes', $reloadValues)) { $_currProduct = Mage::registry('product'); if (!is_null(Mage::registry('product'))) { Mage::unregister('product'); } Mage::register('product', $simple); $confData[$strKey]['attributes'] = Mage::app()->getLayout()->createBlock('catalog/product_view_attributes', 'product.attributes.child', array('template' => "catalog/product/view/attributes.phtml"))->setProduct($simple)->toHtml(); if (!is_null(Mage::registry('product'))) { Mage::unregister('product'); } Mage::register('product', $_currProduct); } $confData[$strKey]['not_is_in_stock'] = !$simple->isSaleable(); //$confData[$strKey]['sku' ] = $simple->getSku(); if ($_useSimplePrice) { $tierPriceHtml = $this->getTierPriceHtml($simple); $confData[$strKey]['price_html'] = str_replace('product-price-' . $simple->getId(), 'product-price-' . $this->getProduct()->getId(), $this->getPriceHtml($simple) . $tierPriceHtml); $confData[$strKey]['price_clone_html'] = str_replace('product-price-' . $simple->getId(), 'product-price-' . $this->getProduct()->getId(), $this->getPriceHtml($simple, false, '_clone') . $tierPriceHtml); // the price value is required for product list/grid $confData[$strKey]['price'] = $simple->getFinalPrice(); } if ($simple->getImage() && $simple->getImage() != "no_selection" && in_array('image', $reloadValues)) { $confData[$strKey]['media_url'] = $this->getUrl('amconf/ajax', array('id' => $simple->getId())); if (Mage::getStoreConfig('amconf/general/oneselect_reload')) { $k = $strKey; if (strpos($strKey, ',')) { $k = substr($strKey, 0, strpos($strKey, ',')); } if (!(array_key_exists($k, $confData) && array_key_exists('media_url', $confData[$k]))) { $confData[$k]['media_url'] = $confData[$strKey]['media_url']; } } else { //for changing only after first select } } elseif ($noimgUrl) { $confData[$strKey]['noimg_url'] = $noimgUrl; } //for >3 if (Mage::getStoreConfig('amconf/general/oneselect_reload')) { $pos = strpos($strKey, ","); if ($pos) { $pos = strpos($strKey, ",", $pos + 1); if ($pos) { $newKey = substr($strKey, 0, $pos); $confData[$newKey] = $confData[$strKey]; } } } } } if (Mage::getStoreConfig('amconf/general/show_clear')) { $html = '<a href="#" onclick="javascript: spConfig.clearConfig(); return false;">' . $this->__('Reset Configuration') . '</a>' . $html; } $html = '<script type="text/javascript"> var amConfAutoSelectAttribute = ' . intval(Mage::getStoreConfig('amconf/general/auto_select_attribute')) . '; confData = new AmConfigurableData(' . Zend_Json::encode($confData) . '); confData.textNotAvailable = "' . $this->__('Choose previous option please...') . '"; confData.mediaUrlMain = "' . $this->getUrl('amconf/ajax', array('id' => $this->getProduct()->getId())) . '"; confData.oneAttributeReload = "' . (bool) Mage::getStoreConfig('amconf/general/oneselect_reload') . '"; confData.imageContainer = "' . Mage::getStoreConfig('amconf/general/image_container') . '"; confData.useSimplePrice = "' . intval($_useSimplePrice) . '"; </script>' . $html; if (Mage::getStoreConfig('amconf/general/hide_dropdowns')) { //$html .= '<script type="text/javascript">Event.observe(window, \'load\', spConfig.processEmpty);</script>'; } } } return $html; }
protected function _afterToHtml($html) { $html = parent::_afterToHtml($html); if ('product.info.options.configurable' == $this->getNameInLayout()) { $html = str_replace('super-attribute-select', 'no-display super-attribute-select', $html); $_product = $this->getProduct(); $_useSimplePrice = Mage::helper('amconf')->getConfigUseSimplePrice() == 2 || (Mage::helper('amconf')->getConfigUseSimplePrice() == 1 and $_product->getData('amconf_simple_price')) ? true : false; $id = $_product->getEntityId(); $imageSizeAtCategoryPageX = Mage::getStoreConfig('amconf/list/main_image_list_size_x'); $imageSizeAtCategoryPageY = Mage::getStoreConfig('amconf/list/main_image_list_size_y'); $parentImage = (string) $this->helper('catalog/image')->init($_product, 'small_image')->resize($imageSizeAtCategoryPageX, $imageSizeAtCategoryPageY); $productUrl = $_product->getProductUrl(); $productUrl = substr($productUrl, strrpos($productUrl, "/")); $confData = array('textNotAvailable' => $this->__('Choose previous option please...'), 'useSimplePrice' => intval($_useSimplePrice), 'url' => $productUrl, 'onclick' => Mage::getStoreConfig('amconf/product_image_size/have_button') ? Mage::helper('checkout/cart')->getAddUrl($_product) : ""); $simpleProducts = $this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $_product); if ($this->_currentAttributes) { $this->_currentAttributes = array_unique($this->_currentAttributes); foreach ($simpleProducts as $simple) { /* @var $simple Mage_Catalog_Model_Product */ $key = array(); foreach ($this->_currentAttributes as $attributeCode) { $key[] = $simple->getData($attributeCode); } if ($key) { $strKey = implode(',', $key); $confData[$strKey] = array(); if (!('no_selection' == $simple->getSmallImage() || '' == $simple->getSmallImage())) { $confData[$strKey]['small_image'] = (string) $this->helper('catalog/image')->init($simple, 'small_image')->resize($imageSizeAtCategoryPageX, $imageSizeAtCategoryPageY); $confData[$strKey]['parent_image'] = $parentImage; if (Mage::getStoreConfig('amconf/general/oneselect_reload')) { $k = $strKey; if (strpos($strKey, ',') > 0) { $k = substr($strKey, 0, strpos($strKey, ',')); } if (!(array_key_exists($k, $confData) && array_key_exists('small_image', $confData[$k]))) { $confData[$k]['small_image'] = $confData[$strKey]['small_image']; $confData[$k]['parent_image'] = $confData[$strKey]['parent_image']; } } else { //for only first } } else { $confData[$strKey]['small_image'] = $parentImage; $confData[$strKey]['parent_image'] = $parentImage; } $confData[$strKey]['not_is_in_stock'] = !$simple->isSaleable(); // the html blocks are required for product view page if ($_useSimplePrice) { $tierPriceHtml = $this->getTierPriceHtml($simple); $confData[$strKey]['price_html'] = $this->getPriceHtml($simple) . $tierPriceHtml; } //for >3 if (Mage::getStoreConfig('amconf/general/oneselect_reload')) { $pos = strpos($strKey, ","); if ($pos) { $pos = strpos($strKey, ",", $pos + 1); if ($pos) { $newKey = substr($strKey, 0, $pos); $confData[$newKey] = $confData[$strKey]; } } } } } $html = '<script type="text/javascript"> confData[' . $id . '] = new AmConfigurableData(' . Zend_Json::encode($confData) . '); amRequaredField = "' . $this->__('↑ This is a required field.') . '"; </script>' . $html; } } return $html; }
protected function _afterToHtml($html) { $attributeIdsWithImages = Mage::registry('amconf_images_attrids'); $html = parent::_afterToHtml($html); if ('product.info.options.configurable' == $this->getNameInLayout()) { if (Mage::getStoreConfig('amconf/general/hide_dropdowns')) { if (!empty($attributeIdsWithImages)) { foreach ($attributeIdsWithImages as $attrIdToHide) { $html = preg_replace('@(id="attribute' . $attrIdToHide . ')(-)?([0-9]*)(")(\\s+)(class=")(.*?)(super-attribute-select)(-)?([0-9]*)@', '$1$2$3$4$5$6$7$8$9$10 no-display', $html); } } } // both config setting and product attribute should be set to "Yes" $_useSimplePrice = (Mage::helper('amconf')->getConfigUseSimplePrice() and $this->getProduct()->getData('amconf_simple_price')) ? true : false; $simpleProducts = $this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct()); if ($this->_optionProducts) { $noimgUrl = Mage::helper('amconf')->getNoimgImgUrl(); $this->_optionProducts = array_values($this->_optionProducts); foreach ($simpleProducts as $simple) { /* @var $simple Mage_Catalog_Model_Product */ $key = array(); for ($i = 0; $i < count($this->_optionProducts); $i++) { foreach ($this->_optionProducts[$i] as $optionId => $productIds) { if (in_array($simple->getId(), $productIds)) { $key[] = $optionId; } } } if ($key) { $strKey = implode(',', $key); // @todo check settings: // array key here is a combination of choosen options $confData[$strKey] = array('short_description' => $this->helper('catalog/output')->productAttribute($simple, nl2br($simple->getShortDescription()), 'short_description'), 'description' => $this->helper('catalog/output')->productAttribute($simple, $simple->getDescription(), 'description')); if (Mage::getStoreConfig('amconf/general/reload_name')) { $confData[$strKey]['name'] = $simple->getName(); } if ($_useSimplePrice) { $tierPriceHtml = $this->getTierPriceHtml($simple); $confData[$strKey]['price_html'] = str_replace('product-price-' . $simple->getId(), 'product-price-' . $this->getProduct()->getId(), $this->getPriceHtml($simple) . $tierPriceHtml); $confData[$strKey]['price_clone_html'] = str_replace('product-price-' . $simple->getId(), 'product-price-' . $this->getProduct()->getId(), $this->getPriceHtml($simple, false, '_clone') . $tierPriceHtml); // the price value is required for product list/grid $confData[$strKey]['price'] = $simple->getFinalPrice(); } if ($simple->getImage() && Mage::getStoreConfig('amconf/general/reload_images')) { $confData[$strKey]['media_url'] = $this->getUrl('amconf/media', array('id' => $simple->getId())); if (Mage::getStoreConfig('amconf/general/oneselect_reload')) { $k = $strKey; if (strpos($strKey, ',')) { $k = substr($strKey, 0, strpos($strKey, ',')); } if (!(array_key_exists($k, $confData) && array_key_exists('media_url', $confData[$k]))) { $confData[$k]['media_url'] = $confData[$strKey]['media_url']; } } else { //for changing only after first select } } elseif ($noimgUrl) { $confData[$strKey]['noimg_url'] = $noimgUrl; } //for >3 if (Mage::getStoreConfig('amconf/general/oneselect_reload')) { $pos = strpos($strKey, ","); if ($pos) { $pos = strpos($strKey, ",", $pos + 1); if ($pos) { $newKey = substr($strKey, 0, $pos); $confData[$newKey] = $confData[$strKey]; } } } } } if (Mage::getStoreConfig('amconf/general/show_clear')) { $html = '<a href="#" onclick="javascript: spConfig.clearConfig(); return false;">' . $this->__('Reset Configuration') . '</a>' . $html; } $html = '<script type="text/javascript"> var showAttributeTitle =' . intval(Mage::getStoreConfig('amconf/general/show_attribute_title')) . '; var amConfAutoSelectAttribute = ' . intval(Mage::getStoreConfig('amconf/general/auto_select_attribute')) . '; confData = new AmConfigurableData(' . Zend_Json::encode($confData) . '); confData.textNotAvailable = "' . $this->__('Choose previous option please...') . '"; confData.mediaUrlMain = "' . $this->getUrl('amconf/media', array('id' => $this->getProduct()->getId())) . '"; confData.oneAttributeReload = "' . (bool) Mage::getStoreConfig('amconf/general/oneselect_reload') . '"; confData.useSimplePrice = "' . intval($_useSimplePrice) . '"; </script>' . $html; if (Mage::getStoreConfig('amconf/general/hide_dropdowns')) { $html .= '<script type="text/javascript">Event.observe(window, \'load\', spConfig.processEmpty);</script>'; } } } return $html; }