linccce

Magento errorneus spot

Mar 19th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.48 KB | None | 0 0
  1. Path: \var\www\app\code\core\Mage\Catalog\Block\Product\View\Options\Type\Select.php
  2.  
  3. <?php
  4. /**
  5.  * Magento
  6.  *
  7.  * NOTICE OF LICENSE
  8.  *
  9.  * This source file is subject to the Open Software License (OSL 3.0)
  10.  * that is bundled with this package in the file LICENSE.txt.
  11.  * It is also available through the world-wide-web at this URL:
  12.  * http://opensource.org/licenses/osl-3.0.php
  13.  * If you did not receive a copy of the license and are unable to
  14.  * obtain it through the world-wide-web, please send an email
  15.  * to [email protected] so we can send you a copy immediately.
  16.  *
  17.  * DISCLAIMER
  18.  *
  19.  * Do not edit or add to this file if you wish to upgrade Magento to newer
  20.  * versions in the future. If you wish to customize Magento for your
  21.  * needs please refer to http://www.magento.com for more information.
  22.  *
  23.  * @category    Mage
  24.  * @package     Mage_Catalog
  25.  * @copyright  Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
  26.  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  27.  */
  28.  
  29.  
  30. /**
  31.  * Product options text type block
  32.  *
  33.  * @category   Mage
  34.  * @package    Mage_Catalog
  35.  * @author     Magento Core Team <[email protected]>
  36.  */
  37. class Mage_Catalog_Block_Product_View_Options_Type_Select
  38.     extends Mage_Catalog_Block_Product_View_Options_Abstract
  39. {
  40.     /**
  41.      * Return html for control element
  42.      *
  43.      * @return string
  44.      */
  45.     public function getValuesHtml()
  46.     {
  47.         $_option = $this->getOption();
  48.         $configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $_option->getId());
  49.         $store = $this->getProduct()->getStore();
  50.  
  51.         if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN
  52.             || $_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
  53.             $require = ($_option->getIsRequire()) ? ' required-entry' : '';
  54.             $extraParams = '';
  55.             $select = $this->getLayout()->createBlock('core/html_select')
  56.                 ->setData(array(
  57.                     'id' => 'select_'.$_option->getId(),
  58.                     'class' => $require.' product-custom-option'
  59.                 ));
  60.             if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN) {
  61.                 $select->setName('options['.$_option->getid().']')
  62.                     ->addOption('', $this->__('-- Please Select --'));
  63.             } else {
  64.                 $select->setName('options['.$_option->getid().'][]');
  65.                 $select->setClass('multiselect'.$require.' product-custom-option');
  66.             }
  67.             foreach ($_option->getValues() as $_value) {
  68.                 $priceStr = $this->_formatPrice(array(
  69.                     'is_percent'    => ($_value->getPriceType() == 'percent'),
  70.                     'pricing_value' => $_value->getPrice(($_value->getPriceType() == 'percent'))
  71.                 ), false);
  72.                 $select->addOption(
  73.                     $_value->getOptionTypeId(),
  74.                     $_value->getTitle() . ' ' . $priceStr . '',
  75.                     array('price' => $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false))
  76.                 );
  77.             }
  78.             if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
  79.                 $extraParams = ' multiple="multiple"';
  80.             }
  81.             if (!$this->getSkipJsReloadPrice()) {
  82.                 $extraParams .= ' onchange="opConfig.reloadPrice()"';
  83.             }
  84.             $select->setExtraParams($extraParams);
  85.  
  86.             if ($configValue) {
  87.                 $select->setValue($configValue);
  88.             }
  89.  
  90.             return $select->getHtml();
  91.         }
  92.  
  93.         if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO
  94.             || $_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX
  95.             ) {
  96.             $selectHtml = '<ul id="options-'.$_option->getId().'-list" class="options-list">';
  97.             $require = ($_option->getIsRequire()) ? ' validate-one-required-by-name' : '';
  98.             $arraySign = '';
  99.             switch ($_option->getType()) {
  100.                 case Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO:
  101.                     $type = 'radio';
  102.                     $class = 'radio';
  103.                     if (!$_option->getIsRequire()) {
  104.                         $selectHtml .= '<li><input type="radio" id="options_' . $_option->getId() . '" class="'
  105.                             . $class . ' product-custom-option" name="options[' . $_option->getId() . ']"'
  106.                             . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"')
  107.                             . ' value="" checked="checked" /><span class="label"><label for="options_'
  108.                             . $_option->getId() . '">' . $this->__('None') . '</label></span></li>';
  109.                     }
  110.                     break;
  111.                 case Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX:
  112.                     $type = 'checkbox';
  113.                     $class = 'checkbox';
  114.                     $arraySign = '[]';
  115.                     break;
  116.             }
  117.             $count = 1;
  118.             foreach ($_option->getValues() as $_value) {
  119.                 $count++;
  120.  
  121.                 $priceStr = $this->_formatPrice(array(
  122.                     'is_percent'    => ($_value->getPriceType() == 'percent'),
  123.                     'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent')
  124.                 ));
  125.  
  126.                 $htmlValue = $_value->getOptionTypeId();
  127.                 if ($arraySign) {
  128.                     $checked = (is_array($configValue) && in_array($htmlValue, $configValue)) ? 'checked' : '';
  129.                 } else {
  130.                     $checked = $configValue == $htmlValue ? 'checked' : '';
  131.                 }
  132.  
  133.                 $selectHtml .= '<li>' . '<input type="' . $type . '" class="' . $class . ' ' . $require
  134.                     . ' product-custom-option"'
  135.                     . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"')
  136.                     . ' name="options[' . $_option->getId() . ']' . $arraySign . '" id="options_' . $_option->getId()
  137.                     . '_' . $count . '" value="' . $htmlValue . '" ' . $checked . ' price="'
  138.                     . $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false) . '" />'
  139.                     . '<span class="label"><label for="options_' . $_option->getId() . '_' . $count . '">'
  140.                     . $_value->getTitle() . ' ' . $priceStr . '</label></span>';
  141.                 if ($_option->getIsRequire()) {
  142.                     $selectHtml .= '<script type="text/javascript">' . '$(\'options_' . $_option->getId() . '_'
  143.                     . $count . '\').advaiceContainer = \'options-' . $_option->getId() . '-container\';'
  144.                     . '$(\'options_' . $_option->getId() . '_' . $count
  145.                     . '\').callbackFunction = \'validateOptionsCallback\';' . '</script>';
  146.                 }
  147.                 $selectHtml .= '</li>';
  148.             }
  149.             $selectHtml .= '</ul>';
  150.  
  151.             return $selectHtml;
  152.         }
  153.     }
  154.  
  155. }
  156.  
  157. What in this can cause this:
  158.  
  159. Example of good output:
  160.  
  161. <li>
  162.     <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">
  163.             <span class="label">
  164.                 <label for="options_385_31">
  165.                     <a href="/media/wysiwyg/swatches/cappuccino.png" title="CappuccinoLeather " rel="lightbox"><img src="/media/wysiwyg/swatches/min/cappuccino.png" alt="Cappuccino" title="Cappuccino Leather">
  166.                         <span style="display:none">Cappuccino Eco Leather</span>
  167.                     </a>
  168.                 </label>
  169.             </span>
  170. <script type="text/javascript">
  171. $('options_385_31').advaiceContainer = 'options-385-container';$('options_385_31').callbackFunction = 'validateOptionsCallback';</script>
  172. </li>
  173.  
  174. Example of wrong output 1 (comment <!-- </label--> appearing out of nowhere):
  175. <li>
  176.     <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">
  177.         <span class="label">
  178.             <label for="options_385_33">
  179.                 <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">
  180.                     <span style="display:none">English Red Eco Leather</span>
  181.                     <!-- </label-->
  182.                 </a>
  183.             </label>
  184.         </span>
  185. <script type="text/javascript">
  186. $('options_385_33').advaiceContainer = 'options-385-container';$('options_385_33').callbackFunction = 'validateOptionsCallback';
  187. </script>
  188.  
  189. Example of wrong output 2 (another comment and duplicated a tag):
  190.  
  191.     <li>
  192.         <a href="/media/wysiwyg/swatches/english-red.png" title="English RedLeather " rel="lightbox">
  193.             <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">
  194.             <span class="label">
  195.                 <label for="options_385_34">
  196.  
  197.                 </label>
  198.             </span>
  199.         </a>
  200.         <a href="/media/wysiwyg/swatches/antique-red.png" title="Antique RedLeather " rel="lightbox">
  201.             <img src="/media/wysiwyg/swatches/min/antique-red.png" alt="Antique Red" title="Antique Red Leather">
  202.             <span style="display:none">Antique Red Eco Leather</span>
  203.             <!-- </label-->
  204.             <script type="text/javascript">$('options_385_34').advaiceContainer = 'options-385-container';
  205.                 $('options_385_34').callbackFunction = 'validateOptionsCallback';
  206.             </script>
  207.         </a>
  208.     </li>
  209.  
  210.  
  211. 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.
  212.  
  213. 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.
  214.  
  215. I'm using this code to parse and generated html data for custom options, this makes sure that everything is perfect:
  216.  
  217. link to parsing code and result var_dump: http://pastebin.com/A9dRuy1m
Advertisement
Add Comment
Please, Sign In to add comment