Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Path: \var\www\app\code\core\Mage\Catalog\Block\Product\View\Options\Type\Select.php
- <?php
- /**
- * Magento
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to [email protected] so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade Magento to newer
- * versions in the future. If you wish to customize Magento for your
- * needs please refer to http://www.magento.com for more information.
- *
- * @category Mage
- * @package Mage_Catalog
- * @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- */
- /**
- * Product options text type block
- *
- * @category Mage
- * @package Mage_Catalog
- * @author Magento Core Team <[email protected]>
- */
- class Mage_Catalog_Block_Product_View_Options_Type_Select
- extends Mage_Catalog_Block_Product_View_Options_Abstract
- {
- /**
- * Return html for control element
- *
- * @return string
- */
- public function getValuesHtml()
- {
- $_option = $this->getOption();
- $configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $_option->getId());
- $store = $this->getProduct()->getStore();
- if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN
- || $_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
- $require = ($_option->getIsRequire()) ? ' required-entry' : '';
- $extraParams = '';
- $select = $this->getLayout()->createBlock('core/html_select')
- ->setData(array(
- 'id' => 'select_'.$_option->getId(),
- 'class' => $require.' product-custom-option'
- ));
- if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN) {
- $select->setName('options['.$_option->getid().']')
- ->addOption('', $this->__('-- Please Select --'));
- } else {
- $select->setName('options['.$_option->getid().'][]');
- $select->setClass('multiselect'.$require.' product-custom-option');
- }
- foreach ($_option->getValues() as $_value) {
- $priceStr = $this->_formatPrice(array(
- 'is_percent' => ($_value->getPriceType() == 'percent'),
- 'pricing_value' => $_value->getPrice(($_value->getPriceType() == 'percent'))
- ), false);
- $select->addOption(
- $_value->getOptionTypeId(),
- $_value->getTitle() . ' ' . $priceStr . '',
- array('price' => $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false))
- );
- }
- if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
- $extraParams = ' multiple="multiple"';
- }
- if (!$this->getSkipJsReloadPrice()) {
- $extraParams .= ' onchange="opConfig.reloadPrice()"';
- }
- $select->setExtraParams($extraParams);
- if ($configValue) {
- $select->setValue($configValue);
- }
- return $select->getHtml();
- }
- if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO
- || $_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX
- ) {
- $selectHtml = '<ul id="options-'.$_option->getId().'-list" class="options-list">';
- $require = ($_option->getIsRequire()) ? ' validate-one-required-by-name' : '';
- $arraySign = '';
- switch ($_option->getType()) {
- case Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO:
- $type = 'radio';
- $class = 'radio';
- if (!$_option->getIsRequire()) {
- $selectHtml .= '<li><input type="radio" id="options_' . $_option->getId() . '" class="'
- . $class . ' product-custom-option" name="options[' . $_option->getId() . ']"'
- . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"')
- . ' value="" checked="checked" /><span class="label"><label for="options_'
- . $_option->getId() . '">' . $this->__('None') . '</label></span></li>';
- }
- break;
- case Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX:
- $type = 'checkbox';
- $class = 'checkbox';
- $arraySign = '[]';
- break;
- }
- $count = 1;
- foreach ($_option->getValues() as $_value) {
- $count++;
- $priceStr = $this->_formatPrice(array(
- 'is_percent' => ($_value->getPriceType() == 'percent'),
- 'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent')
- ));
- $htmlValue = $_value->getOptionTypeId();
- if ($arraySign) {
- $checked = (is_array($configValue) && in_array($htmlValue, $configValue)) ? 'checked' : '';
- } else {
- $checked = $configValue == $htmlValue ? 'checked' : '';
- }
- $selectHtml .= '<li>' . '<input type="' . $type . '" class="' . $class . ' ' . $require
- . ' product-custom-option"'
- . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"')
- . ' name="options[' . $_option->getId() . ']' . $arraySign . '" id="options_' . $_option->getId()
- . '_' . $count . '" value="' . $htmlValue . '" ' . $checked . ' price="'
- . $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false) . '" />'
- . '<span class="label"><label for="options_' . $_option->getId() . '_' . $count . '">'
- . $_value->getTitle() . ' ' . $priceStr . '</label></span>';
- if ($_option->getIsRequire()) {
- $selectHtml .= '<script type="text/javascript">' . '$(\'options_' . $_option->getId() . '_'
- . $count . '\').advaiceContainer = \'options-' . $_option->getId() . '-container\';'
- . '$(\'options_' . $_option->getId() . '_' . $count
- . '\').callbackFunction = \'validateOptionsCallback\';' . '</script>';
- }
- $selectHtml .= '</li>';
- }
- $selectHtml .= '</ul>';
- return $selectHtml;
- }
- }
- }
- What in this can cause this:
- Example of good output:
- <li>
- <input type="radio" class="radio validate-one-required-by-name product-custom-option" onclick="opConfig.reloadPrice()" name="options[385]" id="options_385_31" value="5666" price="0">
- <span class="label">
- <label for="options_385_31">
- <a href="/media/wysiwyg/swatches/cappuccino.png" title="CappuccinoLeather " rel="lightbox"><img src="/media/wysiwyg/swatches/min/cappuccino.png" alt="Cappuccino" title="Cappuccino Leather">
- <span style="display:none">Cappuccino Eco Leather</span>
- </a>
- </label>
- </span>
- <script type="text/javascript">
- $('options_385_31').advaiceContainer = 'options-385-container';$('options_385_31').callbackFunction = 'validateOptionsCallback';</script>
- </li>
- Example of wrong output 1 (comment <!-- </label--> appearing out of nowhere):
- <li>
- <input type="radio" class="radio validate-one-required-by-name product-custom-option" onclick="opConfig.reloadPrice()" name="options[385]" id="options_385_33" value="5668" price="0">
- <span class="label">
- <label for="options_385_33">
- <a href="/media/wysiwyg/swatches/english-red.png" title="English RedLeather " rel="lightbox"><img src="/media/wysiwyg/swatches/min/english-red.png" alt="English Red" title="English Red Leather">
- <span style="display:none">English Red Eco Leather</span>
- <!-- </label-->
- </a>
- </label>
- </span>
- <script type="text/javascript">
- $('options_385_33').advaiceContainer = 'options-385-container';$('options_385_33').callbackFunction = 'validateOptionsCallback';
- </script>
- Example of wrong output 2 (another comment and duplicated a tag):
- <li>
- <a href="/media/wysiwyg/swatches/english-red.png" title="English RedLeather " rel="lightbox">
- <input type="radio" class="radio validate-one-required-by-name product-custom-option" onclick="opConfig.reloadPrice()" name="options[385]" id="options_385_34" value="5669" price="0">
- <span class="label">
- <label for="options_385_34">
- </label>
- </span>
- </a>
- <a href="/media/wysiwyg/swatches/antique-red.png" title="Antique RedLeather " rel="lightbox">
- <img src="/media/wysiwyg/swatches/min/antique-red.png" alt="Antique Red" title="Antique Red Leather">
- <span style="display:none">Antique Red Eco Leather</span>
- <!-- </label-->
- <script type="text/javascript">$('options_385_34').advaiceContainer = 'options-385-container';
- $('options_385_34').callbackFunction = 'validateOptionsCallback';
- </script>
- </a>
- </li>
- I'm using extension called multi_product_editor 2.0.0, which only converts serialized array to normal array and inserts that array as mysql data into database, where for each selected product custom options should usually be.
- I've tested a lot if in the input at the a tag title attribute there are two words its fine and in display none span are up to 3 words, everything is generated fine. But if I increase word amount beyond 4. this obscurity happens.
- I'm using this code to parse and generated html data for custom options, this makes sure that everything is perfect:
- link to parsing code and result var_dump: http://pastebin.com/A9dRuy1m
Advertisement
Add Comment
Please, Sign In to add comment