2012-01-05 10 views
0

Magentoサイトのカテゴリ一覧ページでは、ユーザーが製品をクリックしたときにAJAXを介して製品の表示ページを読み込む列があります。画像、タブなどのビューページからすべてのコンテンツを取得できますが、javascript変数として保存されているため、商品の設定可能なオプションを取得できません。Magento:カテゴリページで設定可能なオプションを取得する

どのように私はその情報も取得することができますか?

編集 - 私は、各製品のビューページに移動せずにすべてのオプションを表示することで、ユーザーがカテゴリページから製品を正しく設定できるようにしようとしています。これまでのところ、私はhtmlを手に入れることができましたが、ドロップダウンは空です。すべてのオプション&の価格がビューページにjavascript変数として保存されているためです。だから私の質問は、どのように私はこれらのオプションを得るには、AJAXの呼び出し&は、ドロップダウンロード&は、製品のビューのページで行うのとまったく同じ方法で動作するのですか?

+0

あなたは、設定オプションの値またはキー(名前/種類/など)を取得しようとしていますか? – shybovycha

+0

ユーザーがオプションを選択し、価格が自動的に更新されるインターフェイスを含むすべてを取得しようとしています。私はそれのためのHTMLを得ることができるが、オプションのリストは空です! –

+0

errr ...具体的にはどのような製品/カテゴリから取得しようとしていますか?ちょうど単語「すべて」の意味を得ておらず、それを質問に関連付ける... – shybovycha

答えて

1

MagentoはJSを使用します。構成可能な製品をレンダリングするには、Mage_Catalog_Block_Product_View_Type_Configurableクラスを使用します。そして、そのgetJsonConfig()メソッドに興味があるはずです。あなたが言ったように、それはapp/design/frontend/base/default/template/catalog/product/view/type/options/configurable.phtmlテンプレート内でmagickを行うjavascriptコードをレンダリングするために使用されます。それがどのように見えるのブラウザで

<script type="text/javascript"> 
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 
</script> 

<script type="text/javascript"> 
    var denyProduct = {"62":["12","9"]}   
    var spConfig = new Product.Config({"attributes":{"70":{"id":"70","code":"manufacturer","label":"Manufacturer","options":[{"id":"11","label":"Fischer","price":"10","oldPrice":"10","products":["61","66"]},{"id":"12","label":"Queen mum","price":"20","oldPrice":"20","products":["62"]}]},"122":{"id":"122","code":"size","label":"Maat","options":[{"id":"9","label":"M","price":"15","oldPrice":"15","products":["61","62"]},{"id":"10","label":"S","price":"0","oldPrice":"0","products":["66"]}]}},"template":"\u20ac\u00a0#{price}","basePrice":"150","oldPrice":"150","productId":"64","chooseText":"Kies een optie...","taxConfig":{"includeTax":true,"showIncludeTax":true,"showBothPrices":false,"defaultTax":19,"currentTax":19,"inclTaxTitle":"Incl. BTW"}}); 
</script> 

そして、すべてのことのjavascriptのオプションを作成するコードは(Mage_Catalog_Block_Product_View_Type_Configurable::getJsonConfig()法)である。

ように見えるテンプレートでそう

$attributes = array(); 
$options = array(); 
$store  = $this->getCurrentStore(); 
$taxHelper = Mage::helper('tax'); 
$currentProduct = $this->getProduct(); 

$preconfiguredFlag = $currentProduct->hasPreconfiguredValues(); 
if ($preconfiguredFlag) { 
    $preconfiguredValues = $currentProduct->getPreconfiguredValues(); 
    $defaultValues  = array(); 
} 

foreach ($this->getAllowProducts() as $product) { 
    $productId = $product->getId(); 

    foreach ($this->getAllowAttributes() as $attribute) { 
     $productAttribute = $attribute->getProductAttribute(); 
     $productAttributeId = $productAttribute->getId(); 
     $attributeValue  = $product->getData($productAttribute->getAttributeCode()); 
     if (!isset($options[$productAttributeId])) { 
      $options[$productAttributeId] = array(); 
     } 

     if (!isset($options[$productAttributeId][$attributeValue])) { 
      $options[$productAttributeId][$attributeValue] = array(); 
     } 
     $options[$productAttributeId][$attributeValue][] = $productId; 
    } 
} 

$this->_resPrices = array(
    $this->_preparePrice($currentProduct->getFinalPrice()) 
); 

foreach ($this->getAllowAttributes() as $attribute) { 
    $productAttribute = $attribute->getProductAttribute(); 
    $attributeId = $productAttribute->getId(); 
    $info = array(
     'id'  => $productAttribute->getId(), 
     'code'  => $productAttribute->getAttributeCode(), 
     'label'  => $attribute->getLabel(), 
     'options' => array() 
    ); 

    $optionPrices = array(); 
    $prices = $attribute->getPrices(); 
    if (is_array($prices)) { 
     foreach ($prices as $value) { 
      if(!$this->_validateAttributeValue($attributeId, $value, $options)) { 
       continue; 
      } 
      $currentProduct->setConfigurablePrice(
       $this->_preparePrice($value['pricing_value'], $value['is_percent']) 
      ); 
      Mage::dispatchEvent(
       'catalog_product_type_configurable_price', 
       array('product' => $currentProduct) 
      ); 
      $configurablePrice = $currentProduct->getConfigurablePrice(); 

      if (isset($options[$attributeId][$value['value_index']])) { 
       $productsIndex = $options[$attributeId][$value['value_index']]; 
      } else { 
       $productsIndex = array(); 
      } 

      $info['options'][] = array(
       'id'  => $value['value_index'], 
       'label'  => $value['label'], 
       'price'  => $configurablePrice, 
       'oldPrice' => $this->_preparePrice($value['pricing_value'], $value['is_percent']), 
       'products' => $productsIndex, 
      ); 
      $optionPrices[] = $configurablePrice; 
      //$this->_registerAdditionalJsPrice($value['pricing_value'], $value['is_percent']); 
     } 
    } 
    /** 
    * Prepare formated values for options choose 
    */ 
    foreach ($optionPrices as $optionPrice) { 
     foreach ($optionPrices as $additional) { 
      $this->_preparePrice(abs($additional-$optionPrice)); 
     } 
    } 
    if($this->_validateAttributeInfo($info)) { 
     $attributes[$attributeId] = $info; 
    } 

    // Add attribute default value (if set) 
    if ($preconfiguredFlag) { 
     $configValue = $preconfiguredValues->getData('super_attribute/' . $attributeId); 
     if ($configValue) { 
      $defaultValues[$attributeId] = $configValue; 
     } 
    } 
} 

$taxCalculation = Mage::getSingleton('tax/calculation'); 
if (!$taxCalculation->getCustomer() && Mage::registry('current_customer')) { 
    $taxCalculation->setCustomer(Mage::registry('current_customer')); 
} 

これらの値をに接続するコード要素はProduct.jsファイル内にあります。

いくつかのカテゴリで使用されているすべての属性を取得したい場合は、解決策を次に示します。変数$_productCollectionにカテゴリの商品が入力されていると仮定します。ですから、$collection変数内(リピートを有する)すべての属性を取得するものと

$setIds = array(); 

foreach ($_productCollection as $k => $product) 
{ 
    $setIds[] = $product->getAttributeSetId(); 
} 

/** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */ 
$collection = Mage::getResourceModel('catalog/product_attribute_collection'); 
$collection 
    ->setItemObjectClass('catalog/resource_eav_attribute') 
    ->setAttributeSetFilter($setIds) 
    ->addStoreLabel(Mage::app()->getStore()->getId()) 
    ->setOrder('position', 'ASC'); 

$collection->load(); 

:次に、あなたは、このパフォーマンス破りのコードを実行することができます。

願わくば、これは何とかお手伝いします。

+0

詳細な応答をありがとうございます。私は今オプションがどこから来たのかをはっきりと理解しています。しかし、私はこのソリューションを使用することはできませんが、あなたが言及したように、パフォーマンスが壊れているので、私は恐れています!私はこれを達成する他の方法を見なければならないでしょう。もう一度ありがとう!感謝します。 –

+0

'$ _productCollection'変数やwhile属性のコレクションをキャッシュすると、パフォーマンスが向上します;)オフィスでmagickを実行すると、Magentoでの試合のパフォーマンスは気にしません。 – shybovycha

0

各製品には多くのオプションがあるため、これにはかなりのサーバーリソースが必要になります。最も良い方法は、ajaxを使用して、要求されたときにのみすべてのオプションをロードすることです。私は色を最初にロードするこの拡張機能を見つけました。その後、マウスオーバーするとすべての製品オプションが表示されます。

http://www.consofas.com/plugins/options-quickview-for-configurable-products-in-magento/

関連する問題