删除自定义选项"无"

时间:2014-10-07 15:41:35

标签: magento

我是Magento的新手。我们已经创建了一个自定义选项。但是每当我们选择“径向”时,它总是显示我们需要删除的“无”选项。根据我的理解,我从Magento Core中提取了一些代码。

这是我需要编辑的HTML:

<dt><label>Add a Display Case:</label></dt>
<dd class="last">
    <div class="input-box">
        <ul id="options-7-list" class="options-list"><li><input type="radio" id="options_7" class="radio product-custom-option" name="options[7]" onclick="opConfig.reloadPrice()" value="" checked="checked" /><span class="label"><label for="options_7">None</label></span></li><li><input type="radio" class="radio  product-custom-option" onclick="opConfig.reloadPrice()" name="options[7]" id="options_7_2" value="19"  price="45" /><span class="label"><label for="options_7_2">Acrylic Cube <span class="price-notice">+<span class="price">$45.00</span></span></label></span></li><li><input type="radio" class="radio  product-custom-option" onclick="opConfig.reloadPrice()" name="options[7]" id="options_7_3" value="20"  price="75" /><span class="label"><label for="options_7_3">Lucite Case <span class="price-notice">+<span class="price">$75.00</span></span></label></span></li></ul>            </div>
</dd>

这是我认为它输出的地方......

<?php
class OptionExtended_Block_Product_View_Js extends  Mage_Catalog_Block_Product_View_Options
{
    protected $config = array();
    protected $thumbnailDirUrl = '';        
    protected $pickerImageDirUrl = '';

    protected function _construct()
    {   

        $children = array();        
        $sd = array();  
        $configValues = array();
        $inPreConfigured = $this->getProduct()->hasPreconfiguredValues();
        $storeId = Mage::app()->getStore()->getId();                        
        $product_id = $this->getProduct()->getId();
        $filter = Mage::getModel('core/email_template_filter');


        $options = $this->getProduct()->getOptions();

        foreach ($options as $option){
          if (!is_null($option->getLayout())){
              $id = (int) $option->getOptionId();

              if (!is_null($option->getRowId()))                    
                  $option_id_by_row_id[$option->getTemplateId()][(int) $option->getRowId()] = $id;

              $this->config[0][$id][0] = $option->getNote() != '' ? $filter->filter($option->getNote()) : '';   
              $this->config[0][$id][1] = $option->getLayout();                  
              $this->config[0][$id][2] = (int) $option->getPopup(); 

                if ($inPreConfigured){
                    $configValues[$id] = array();           
                    if (is_null($option->getRowId())){
                        $configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $id);    
                        if (!is_null($configValue))
                            $configValues[$id] = (array) $configValue;                  
                    }
                } else { 
                    $sd[$option->getTemplateId()][$id] = explode(',', $option->getSelectedByDefault());
                }   


              if (!is_null($option->getValues())){                        
              foreach ($option->getValues() as $value) {
                  $valueId = (int) $value->getOptionTypeId();
                  $this->prepareImages($value->getImage()); 

                  $rowId = (int) $value->getRowId();                            
                    $valueId_by_row_id[$value->getTemplateId()][$rowId] = $valueId;

                  $children[$value->getTemplateId()][$valueId] = explode(',', $value->getChildren());                       
                  $this->config[1][$valueId][0] = $value->getImage();                       
                  $this->config[1][$valueId][1] = $value->getDescription() != '' ? $filter->filter($value->getDescription()) : '';  
                  $this->config[1][$valueId][2] = array();  
                  $this->config[1][$valueId][3] = array();              
              }
              }     
            }                               
        }


        $options = Mage::getModel('optionextended/option')
            ->getCollection()
            ->joinNotes($storeId)               
            ->addFieldToFilter('product_id', $product_id);      
        foreach ($options as $option){
            $id = (int) $option->getOptionId();

            if (!is_null($option->getRowId()))                  
                $option_id_by_row_id['orig'][(int) $option->getRowId()] = $id;

            $this->config[0][$id][0] = $option->getNote() != '' ? $filter->filter($option->getNote()) : ''; 
            $this->config[0][$id][1] = $option->getLayout();                    
            $this->config[0][$id][2] = (int) $option->getPopup();   

            if ($inPreConfigured){
                $configValues[$id] = array();           
                if (is_null($option->getRowId())){
                    $configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $id);    
                    if (!is_null($configValue))
                        $configValues[$id] = (array) $configValue;                  
                }
            } else { 
                $sd['orig'][$id] = explode(',', $option->getSelectedByDefault());
            }           

        }   

        $values = Mage::getModel('optionextended/value')
            ->getCollection()
            ->joinDescriptions($storeId)                
            ->addFieldToFilter('product_id', $product_id);  
        foreach ($values as $value) {
            $valueId = (int) $value->getOptionTypeId();
            $this->prepareImages($value->getImage());   

            $rowId = (int) $value->getRowId();                          
            $valueId_by_row_id['orig'][$rowId] = $valueId;

            $children['orig'][$valueId] = explode(',', $value->getChildren());                      
            $this->config[1][$valueId][0] = $value->getImage();                     
            $this->config[1][$valueId][1] = $value->getDescription() != '' ? $filter->filter($value->getDescription()) : '';    
            $this->config[1][$valueId][2] = array();    
            $this->config[1][$valueId][3] = array();                
        }   




        if ($inPreConfigured){
            foreach ($configValues as $optionId => $v){
                $this->config[0][$optionId][3] = array();           
                foreach($v as $valueId)
                        $this->config[0][$optionId][3][] = (int) $valueId;                              
            }       
        } else {        
            foreach ($sd as $templateId => $v){ 
                foreach ($v as $optionId => $vv){
                    $this->config[0][$optionId][3] = array();                   
                    foreach($vv as $rowId)
                        if ($rowId != '')
                            $this->config[0][$optionId][3][] = $valueId_by_row_id[$templateId][(int)$rowId];
                }
            }
        }


        foreach ($children as $templateId => $v){
          foreach ($v as $valueId => $vv){
              foreach ($vv as $rowId){
              if ($rowId != ''){
                    if (isset($option_id_by_row_id[$templateId][(int)$rowId]))
                        $this->config[1][$valueId][2][] = $option_id_by_row_id[$templateId][(int)$rowId];
                    else                
                        $this->config[1][$valueId][3][] = $valueId_by_row_id[$templateId][(int)$rowId]; 
                    }                   
              }
          }
        }       

    }



    public function getConfig()
    {   
        return Zend_Json::encode($this->config);
    }


    public function prepareImages($image)
    {   
        if ($image){
            $thumbnailUrl = $this->makeThumbnail($image);           
            $pickerImageUrl = $this->makePickerImage($image);
            if ($this->thumbnailDirUrl == ''){
                $this->thumbnailDirUrl = str_replace($image, '', $thumbnailUrl);                    
                $this->pickerImageDirUrl = str_replace($image, '', $pickerImageUrl);                                
            }   
        }
    }


    public function makeThumbnail($image)
    {   
        $thumbnailUrl = $this->helper('catalog/image')
            ->init($this->getProduct(), 'thumbnail', $image)
            ->keepFrame(true)
// Uncomment the following line to set Thumbnail RGB Background Color:
//          ->backgroundColor(array(246,246,246))   

// Set Thumbnail Size:          
            ->resize(100,100)
            ->__toString();
        return $thumbnailUrl;
    }       


    public function makePickerImage($image)
    {   
            $pickerImageUrl = $this->helper('catalog/image')
                ->init($this->getProduct(), 'thumbnail', $image)
                ->keepFrame(false)
                ->resize(30,30)
                ->__toString();         
            return $pickerImageUrl;
        }   

    public function getThumbnailDirUrl()
    {           
            return $this->thumbnailDirUrl;
        }   


    public function getPickerImageDirUrl()
    {           
            return $this->pickerImageDirUrl;
        }

    public function getPlaceholderUrl()
    {
            return Mage::getDesign()->getSkinUrl($this->helper('catalog/image')->init($this->getProduct(), 'small_image')->getPlaceholder());
        }   


    public function getProductBaseMediaUrl()
    {           
            return Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl();
        }   

    public function getInPreconfigured()
    {           
            return $this->getProduct()->hasPreconfiguredValues() ? 'true' : 'false';
        }   


}

5 个答案:

答案 0 :(得分:0)

我认为你做错了什么。

Magento Custom Options

从这张图片中,您可以看到您可以添加随后显示在前端的选项。只会显示这些选项!

您无需在Magento Core代码中进行任何更改即可解决问题。

如果您仍有问题,请尽可能为我们提供Magento网上商店的截图和网址。

答案 1 :(得分:0)

您是否正在使用SWMS Option Image等扩展程序向您的自定义选项添加图片等附加内容?此扩展名添加了None选项。

您需要进入社区文件夹并选择您的扩展程序并编辑default.php并将“无”更改为“标准”或类似内容。

对于SWMS选项图像,我更改了: /community/Swms/Optionimage/Block/Product/View/Options/Type/Select.php

<label for="options_'.$_option->getId().'">' . $this->__('Standard') . '</label>

答案 2 :(得分:0)

我有另一个解决方案。编辑csv文件。 Mage_Catalog.csv。为None添加一行,并将单词Standard添加到下一列。

答案 3 :(得分:0)

通过修改此文件解决了问题: 应用程序/代码/本地/法师/目录/座/产品/查看/选项/类型/ Select.php 修改后的行102-106

<?php
            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;
            }
?>

答案 4 :(得分:0)

我有同样的问题,如果我不需要该字段,我也会发现magento将生成“ None”选项。快速解决方案,但不建议使用CSS隐藏该选项。