如何在产品页面Magento上显示定制选项下拉菜单? [英] How to display cutom options dropdown on the product page Magento?

查看:87
本文介绍了如何在产品页面Magento上显示定制选项下拉菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定制的Magento产品页面显示,所以没有颜色,大小等选择器.

I have a custom made Magento product page display, so there's no where selectors of color,size ... etc.

在产品详细信息->自定义选项中,我选择了颜色,如果现在我要购买该产品,则需要选择颜色,但是现在没有下拉列表. 我也看不到未在产品页面中选择该选项的错误,只有当我访问了空的购物车,但显示错误时,我才能看到它.

In the product details -> custom options, I've made the Color option, and right now if i try to buy that product, is required to select the color but there's no drop down for it right now. also i can't see the error of the option is not selected in the product page, i can see it only when i access the cart which is empty but it shows the errors.

所以我需要的是:

1.如何从产品本身的自定义选项中显示自定义选项颜色" [下拉]. 2.在产品页面上显示错误,例如产品缺货或未选择颜色选项".

1.How to show the custom option "colors" from the custom options in the products itself [drop down]. 2.Display the errors on the product page like "the product is out of stock or the color option is not selected".

提前谢谢!

更新:

当我想添加到购物车时,我仍在处理此代码,但仍然说未选中该选项,这是怎么回事?

I got it working with this code BUT when i want to add to cart still say that the option is not selected, what's wrong with it?

    $productSku = $_product->getSku();
$product = Mage::getModel('catalog/product');
$productId = $product->getIdBySku( $productSku );

$product = Mage::getModel("catalog/product")->load($productId);

$attVal = $product->getOptions();

$optStr = "";

// loop through the options
foreach($attVal as $optionKey => $optionVal) {

//$optStr .= "<br/>";

//$optStr .= $optionVal->getTitle().": ";

$optStr .= "<select style='display:block; clear:both;' name='options[".$optionVal->getId()."]'>";

foreach($optionVal->getValues() as $valuesKey => $valuesVal) {
$optStr .= "<option value='".$valuesVal->getId()."'>".$valuesVal->getTitle()."</option>";
}

$optStr .= "</select>";

}

echo($optStr );

更新Amit: var_dump($attVal);

array(1) {
  [1]=>
  object(Mage_Catalog_Model_Product_Option)#469 (19) {
    ["_product":protected]=>
    object(Mage_Catalog_Model_Product)#74 (32) {
      ["_cacheTag":protected]=>
      string(15) "catalog_product"
      ["_eventPrefix":protected]=>
      string(15) "catalog_product"
      ["_eventObject":protected]=>
      string(7) "product"
      ["_canAffectOptions":protected]=>
      bool(false)
      ["_typeInstance":protected]=>
      NULL
      ["_typeInstanceSingleton":protected]=>
      NULL
      ["_linkInstance":protected]=>
      NULL
      ["_customOptions":protected]=>
      array(0) {
      }
      ["_urlModel":protected]=>
      NULL
      ["_errors":protected]=>
      array(0) {
      }
      ["_optionInstance":protected]=>
      object(Mage_Catalog_Model_Product_Option)#286 (19) {
        ["_product":protected]=>
        NULL
        ["_options":protected]=>
        array(0) {
        }
        ["_valueInstance":protected]=>
        NULL
        ["_values":protected]=>
        array(0) {
        }
        ["_eventPrefix":protected]=>
        string(13) "core_abstract"
        ["_eventObject":protected]=>
        string(6) "object"
        ["_resourceName":protected]=>
        string(22) "catalog/product_option"
        ["_resource":protected]=>
        NULL
        ["_resourceCollectionName":protected]=>
        string(33) "catalog/product_option_collection"
        ["_cacheTag":protected]=>
        bool(false)
        ["_dataSaveAllowed":protected]=>
        bool(true)
        ["_isObjectNew":protected]=>
        NULL
        ["_data":protected]=>
        array(0) {
        }
        ["_hasDataChanges":protected]=>
        bool(false)
        ["_origData":protected]=>
        NULL
        ["_idFieldName":protected]=>
        NULL
        ["_isDeleted":protected]=>
        bool(false)
        ["_oldFieldsMap":protected]=>
        array(0) {
        }
        ["_syncFieldsMap":protected]=>
        array(0) {
        }
      }
      ["_options":protected]=>
      *RECURSION*
      ["_reservedAttributes":protected]=>
      NULL
      ["_isDuplicable":protected]=>
      bool(true)
      ["_calculatePrice":protected]=>
      bool(true)
      ["_defaultValues":protected]=>
      array(1) {
        ["url_path"]=>
        string(47) "charger.html"
      }
      ["_storeValuesFlags":protected]=>
      array(1) {
        ["url_path"]=>
        bool(true)
      }
      ["_lockedAttributes":protected]=>
      array(0) {
      }
      ["_isDeleteable":protected]=>
      bool(true)
      ["_isReadonly":protected]=>
      bool(false)
      ["_resourceName":protected]=>
      string(15) "catalog/product"
      ["_resource":protected]=>
      NULL
      ["_resourceCollectionName":protected]=>
      string(26) "catalog/product_collection"
      ["_dataSaveAllowed":protected]=>
      bool(true)
      ["_isObjectNew":protected]=>
      NULL
      ["_data":protected]=>
      array(71) {
        ["entity_id"]=>
        string(1) "9"
        ["entity_type_id"]=>
        string(1) "4"
        ["attribute_set_id"]=>
        string(1) "4"
        ["type_id"]=>
        string(6) "simple"
        ["sku"]=>
        string(6) "123456"
        ["has_options"]=>
        string(1) "1"
        ["required_options"]=>
        string(1) "1"
        ["created_at"]=>
        string(19) "2012-10-19 15:15:38"
        ["updated_at"]=>
        string(19) "2013-03-18 14:19:05"
        ["color"]=>
        NULL
        ["status"]=>
        string(1) "1"
        ["visibility"]=>
        string(1) "4"
        ["enable_googlecheckout"]=>
        string(1) "1"
        ["tax_class_id"]=>
        string(1) "4"
        ["featured"]=>
        string(1) "0"
        ["news_from_date"]=>
        NULL
        ["news_to_date"]=>
        NULL
        ["special_from_date"]=>
        string(19) "2012-10-17 00:00:00"
        ["special_to_date"]=>
        string(19) "2013-04-30 00:00:00"
        ["custom_design_from"]=>
        NULL
        ["custom_design_to"]=>
        NULL
        ["enjoyby"]=>
        NULL
        ["name"]=>
        string(42) "Charger"
        ["meta_title"]=>
        NULL
        ["meta_description"]=>
        NULL
        ["image"]=>
        string(34) "/3/1/31gzr5vwlwl._sl500_aa300_.jpg"
        ["small_image"]=>
        string(34) "/3/1/31gzr5vwlwl._sl500_aa300_.jpg"
        ["thumbnail"]=>
        string(34) "/3/1/31gzr5vwlwl._sl500_aa300_.jpg"
        ["url_key"]=>
        string(42) "charger"
        ["url_path"]=>
        string(47) "charger.html"
        ["custom_design"]=>
        NULL
        ["page_layout"]=>
        NULL
        ["options_container"]=>
        string(10) "container2"
        ["image_label"]=>
        NULL
        ["small_image_label"]=>
        NULL
        ["thumbnail_label"]=>
        NULL
        ["country_of_manufacture"]=>
        NULL
        ["msrp_enabled"]=>
        string(1) "2"
        ["msrp_display_actual_price_type"]=>
        string(1) "4"
        ["gift_message_available"]=>
        NULL
        ["starttime"]=>
        string(8) "11:59 PM"
        ["time"]=>
        string(8) "11:59 PM"
        ["target_number"]=>
        string(1) "1"
        ["percustomer"]=>
        string(1) "0"
        ["for_friend"]=>
        string(1) "0"
        ["dealcity"]=>
        string(5) "3,4,5"
        ["dealcategory"]=>
        string(1) "6"
        ["customeremail"]=>
        string(18) "test@test.com"
        ["questions"]=>
        string(10) "7185696643"
        ["customer_website"]=>
        string(16) "Electronics"
        ["merchant"]=>
        string(1) "1"
        ["price"]=>
        string(7) "19.9900"
        ["special_price"]=>
        string(6) "0.9900"
        ["weight"]=>
        string(6) "0.2000"
        ["msrp"]=>
        NULL
        ["description"]=>
        string(914) "

推荐答案

使用以下代码获取自定义选项

Use below code to get the custom options

<?php foreach($_product->getOptions() as $options) :?>
    <?php if ($options->getType() == 'drop_down'): ?>
        <select class="required-entry product-custom-option" id="select_<?php echo $options->getOptionId() ?>" name="options[<?php echo $options->getOptionId() ?>]">
            <option value="">-- Please Select --</option>
            <?php foreach ($options->getValues() as $value): ?>
                <option value="<?php echo $value['option_type_id']; ?>"><?php echo $value['title']; ?></option>
            <?php endforeach; ?>
        </select>
    <?php endif; ?>
<?php endforeach; ?>

您还可以根据选项类型进行修改

You can also modify according option type

这篇关于如何在产品页面Magento上显示定制选项下拉菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆