2016-03-24 13 views
0

私はMagento 1.9.2.4(私のテストページでは1.9.2.3)を使用していますが、オプションと製品がそれぞれ1つ設定可能な子製品の配信時間が異なります)。私は顧客がオプションを選択したときに更新したい "delivery_time"という属性を作成しました。これを達成するために、私が使用するコードスニペットがいくつか見つかりました。しかし、それは正しく更新されていません。ので、ここでMagento 1.9.2 - 構成可能な製品プロセスのカスタム属性 'delivery_time'を更新してください

は私のアプリ/設計/フロントエンド/ RWD/fitgmbh /テンプレート/カタログ/製品/ビュー/タイプ/オプション/ configurable.phtml

<?php 
$_product = $this->getProduct(); 
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); 
?> 
<?php if ($_product->isSaleable() && count($_attributes) && $_product->isConfigurable()):?> 
<dl> 
<?php foreach($_attributes as $_attribute): ?> 
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt> 
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>> 
    <div class="input-box"> 
     <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select" 
       onchange="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this);"> 
      <option><?php echo $this->__('Choose an Option...') ?></option> 
     </select> 
    </div> 
</dd> 
<?php endforeach; ?> 
</dl> 
<script type="text/javascript"> 
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 
</script> 
<?php endif;?> 
<?php 
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); 
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); 
$productMap = array(); 
foreach($col as $simpleProduct){ 
$productMap[$simpleProduct->getId()] = $simpleProduct->getDeliveryTime(); 
} 
if($_product->getTypeId() == "configurable"): 
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); 
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); 
foreach($simple_collection as $simple_product){ 
    echo $simple_product->getName() . " - " . $simple_product->getDeliveryTime() . "<br>"; 
} 
endif; 
?> 
<script type="text/javascript"> 
document.observe("dom:loaded", function() { 
$("delivery").update("Bitte Optionen wählen"); 
}); 

function changeSku(confAttributeId, sel) { 
var productMap = <?php echo Mage::helper('core')->jsonEncode($productMap);?>; 
var selectedAttributeId = sel.options[sel.selectedIndex].value; 
if (selectedAttributeId) { 
    var options = spConfig.config.attributes[confAttributeId].options; 
    var productId = options.find(function (option) {return option.id == selectedAttributeId}).products[0] 
    $("delivery").update("Lieferzeit: " + productMap[productId]); 
} else { 
    $("delivery").reset(); //just a test ;-) 
} 
} 
</script> 
<?php echo $this->getChildHtml('after') ?> 

であり、私は/アプリ/デザインの出力を示し、

<div id="delivery"></div> 

とフロントエンド/ RWD/fitgmbh /テンプレート/カタログ/製品/ view.phtml私は私の問題を理解するのは難しいかもしれないことを知っているので、私は、私は私のTestpageへのリンクを提供しなければならないと思います。設定可能なブロックには、利用可能なすべてのオプションの組み合わせがリストされています。最後の数字は、my(test)delivery_time(1-12)の略です。このコードが正しく動作するためには、私が何をしなければならないか分かりません。顧客がオプション選択プロセスに「戻る」場合、「最も簡単な」ソリューションの一部は、すべての入力をリセットすることだと考えています。しかし、私のjavascriptのスキルは本当に存在していません。これとは別に、他の配信アップデートも正しいわけではありません。しかし、数時間の試行錯誤の末、少なくとも私はあきらめました。たぶんあなたの誰かが私を助けることができます。私はすべてのヒントのために本当に感謝しています!私は、私が「問題」を適切な方法で記述したことを願っています。

私はChris Rogersの示唆したように、 "Arithon_DeliveryUpdate"というモジュールを作成しましたが、オブザーバまたはルータでモジュールを作成したことはありません。私のモジュールには間違いがあります。少なくともその活性;-)

アプリケーション/コード/ローカル/ Arithon/DeliveryUpdateの/ etc/config.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
<modules> 
    <Arithon_DeliveryUpdate> 
     <version>1.0</version> 
    </Arithon_DeliveryUpdate> 
</modules> 
<frontend> 
    <routers> 
     <catalog> 
      <args> 
       <module>Arithon_DeliveryUpdate</module> 
       <frontName>delivery_time</frontName> 
      </args> 
     </catalog>  
    </routers> 
</config> 

アプリケーション/コード/ローカル/ Arithon/DeliveryUpdate /コントローラ/ DeliveryController.php

別にミスから
<?php 
public function updateAction() { 
$match = 0; 
if ($this->getRequest()->isPost()) { 
    extract($this->getRequest()->getPost()); 
    $_storeId = Mage::app()->getStore()->getId(); 
    $_attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attrId); 
    $_product = Mage::getModel('catalog/product')->load($productId); 
    if ($_product && $_attribute && is_object($_product) && $_product->type_id == 'configurable') { 
     $_attrCode = $_attribute->getData('attribute_code'); 
     $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $_product); 
     foreach($childProducts as $child) { 
      $cId = $child->getId(); 
      $v = Mage::getResourceModel('catalog/product')->getAttributeRawValue($cId, $_attrCode, $storeId); 
      if ($v == $selectValue) { 
       $configAttr = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'delivery_time'); 
       $configAttrId = $configAttr->getId(); 
       $configAttrValue = Mage::getResourceModel('catalog/product')->getAttributeRawValue($cId, 'delivery_time', $storeId); 
       $match = array("attrId" => $configAttrId, "attrValue" => $configAttrValue); 
       break; 
      } 
     }     
    } 
} 
return $match; 
} 
?> 

そして、私の修正configurable.phtml

<?php 
$_product = $this->getProduct(); 
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); 
?> 
<?php if ($_product->isSaleable() && count($_attributes) && $_product->isConfigurable()):?> 
<dl> 
<?php foreach($_attributes as $_attribute): ?> 
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt> 
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>> 
    <div class="input-box"> 
     <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select" onchange="productAddToCartForm.updateDelivery(this, <?php echo $_product->getId() ?>);" name="super_attribute[<?php echo $attrId ?>]" id="attribute<?php echo $attrId ?>" class="required-entry super-attribute-select" 
       onchange="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this) ;"> 
      <option><?php echo $this->__('Choose an Option...') ?></option> 

     </select> 
    </div> 
</dd> 
<?php endforeach; ?> 
</dl> 
<script type="text/javascript"> 
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 
</script> 
<?php endif;?> 
<?php 
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); 
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); 
$productMap = array(); 
foreach($col as $simpleProduct){ 
$productMap[$simpleProduct->getId()] = $simpleProduct->getDeliveryTime(); 
} 
//echo $simpleProduct->getDeliveryTime(); 
if($_product->getTypeId() == "configurable"): 
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); 
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); 
foreach($simple_collection as $simple_product){ 
    echo $simple_product->getName() . " - " . $simple_product->getDeliveryTime() . "<br>"; 
} 
endif; 
?> 
<script type="text/javascript"> 
if (typeof productAddToCartForm != "undefined") { 
productAddToCartForm.updateDelivery= function(select, product_id) { 
    if (select != null && product_id != null && typeof select.selectedIndex != "undefined") { 
     var keyword = 'attribute'; 
     var url = '/deliveryupdate/delivery/update'; // don´t know what to put here 
     var val = select.options[select.selectedIndex].value; 
     var attrId = select.getAttribute("id").replace(keyword, ""); 
     var formData = { 
      selectValue: val, 
      productId: product_id, 
      attrId: attrId 
     }; 

     // Make request to controller which will determine which value the configurable_attr_placeholder 
     jQuery.ajax({ 
      url: url, 
      type: 'POST', 
      data: formData, 
      success: function(data) { 
       // PHP returns string readily convertable to JSON 
       var response = JSON.parse(data); 
       if (typeof response == 'object') { 
        // JSON key values are attrId and attrValue 
        var delivEl = document.getElementById(keyword + response.attrId); 
        if (typeof delivEl != "undefined" && configSel) { 
         delivEl = response.attrValue; 
         break; 
        } 
       } 
      } 
     }); 
    } 
}; 
} 
</script> 
<?php echo $this->getChildHtml('after') ?> 

、このモジュールはACになっています私のカスタム属性「delivery_time」を瞬時に更新して使用できるようにします

<?php echo $_product->getdelivery_time()?> 

私のview.phtmlには?私は使用する必要はありません

<div id="delivery"></div> 

もう何もありませんか?事前

答えて

1

Magentoの1.9で

おかげで、まだ選択のonchangeを処理するためのプロトタイプを使用しています。この機能を次のように拡張することができます:

app/design/frontend/YOUR_INTERFACE/YOUR_THEME/template/catalog/product/view/type/options/configurablePHTML - あなたのonchangeに余分な機能を追加します。

<select onchange="productAddToCartForm.updateDelivery(this, <?php echo $_product->getId() ?>);" name="super_attribute[<?php echo $attrId ?>]" id="attribute<?php echo $attrId ?>" class="required-entry super-attribute-select"> 

を次にJSで、プロトタイプを拡張:

注:そのライブラリも利用可能になりましたので、私もここにjQueryを使用していますMagento 1.9では、私は個人的にAJAX関数が好きです。

通知AJAXを使用してコントローラメソッド(var url = '/YOUR_ROUTER/delivery/update';)を呼び出しています。このメソッドは納品時間を返します。このメソッドのために

あなたはcreate a custom moduleとセットアップイベントルータに必要としている仕事に

だから、アプリ/コード/ローカル/ YOUR/MODULE /コントローラ/ DeliveryController中:

public function updateAction() { 
    $match = 0; 
    if ($this->getRequest()->isPost()) { 
     extract($this->getRequest()->getPost()); 
     $_storeId = Mage::app()->getStore()->getId(); 
     $_attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attrId); 
     $_product = Mage::getModel('catalog/product')->load($productId); 
     if ($_product && $_attribute && is_object($_product) && $_product->type_id == 'configurable') { 
      $_attrCode = $_attribute->getData('attribute_code'); 
      $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $_product); 
      foreach($childProducts as $child) { 
       $cId = $child->getId(); 
       $v = Mage::getResourceModel('catalog/product')->getAttributeRawValue($cId, $_attrCode, $storeId); 
       if ($v == $selectValue) { 
        $configAttr = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'delivery_time'); 
        $configAttrId = $configAttr->getId(); 
        $configAttrValue = Mage::getResourceModel('catalog/product')->getAttributeRawValue($cId, 'delivery_time', $storeId); 
        $match = array("attrId" => $configAttrId, "attrValue" => $configAttrValue); 
        break; 
       } 
      }     
     } 
    } 
    return $match; 
} 

注:これは、設定製品を取得します - すべての中古製品を取得し、それらの配達時間を検索し、それを返します。 JSで使用する準備ができました

これは、正しい配送時間を取得する必要があります。このコントローラを使用して、関連付けられた製品に関する他の情報を返して、他のものを更新することもできます。これはテストされていないコードなので、あなたが立ち往生しているかどうか尋ねてください!

本当に役立ちます。

+0

提案していただきありがとうございます。私はこれをできるだけ早く試みます!私はそれが動作するかどうか、またはあなたが正しくあなたの提案を適用することができない/できない場合、応答音を与えます。再度、感謝します! – CrynosArioch

+0

男の心配はありません! –

+0

私はあなたの提案を使用しようとしましたが、上記のように私のモジュールは正しく動作していません。多分あなたは私の演習をもう一度見ることができますか? – CrynosArioch

関連する問題