1

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

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

所以我需要的是:

1.如何在产品本身的自定义选项中显示自定义选项“颜色”[下拉]。2.在产品页面显示“产品缺货或未选择颜色选项”等错误。

提前致谢!

更新:

我得到它使用此代码但是当我想添加到购物车时仍然说未选择该选项,它有什么问题?

    $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 );

阿米特的更新: 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) "
4

2 回答 2

3

[编辑]

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

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

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

于 2013-03-18T14:59:33.317 回答
0
           <?php if ($_product->isSaleable() && $this->hasOptions()):?>


           <?php echo $this->getChildChildHtml('container2', '', true, true) ?>



           <?php endif;?>
于 2014-01-09T19:38:59.220 回答