2012-03-19 14 views
2

私は今これとしばらく戦ってきました。私は正しくsuccesffuly設定された設定可能な製品を持っています。私はまた、子供に基づいて、この製品の各バージョンで利用可能なサイズと数量に基づいて作成されたテーブルを持っています。ここで参照:dev4.printpartnerships.com/flyer-printingMagento AJAXテーブルリロード製品ページ

このテーブルは現在ロードされているページでレンダリングされ、jQueryを使用してドロップダウンボックスの選択に応じてスワップします。問題は少し遅いので、ドロップダウンに応じてテーブルを動的に再ロードする必要があります。たとえば、ドロップダウン3、用紙を選択すると、潜在的にテーブルがリロードされます。で、しかし、私はそれらをAJAXたい、

public function getMatrixData($requiredAttributeIds = null, $product = null, $stock) 
{ 
    Varien_Profiler::start('CONFIGURABLE:'.__METHOD__); 
    $this->_usedProducts = '_cache_instance_products'; 
    if ($this->getProduct($product)->hasData($this->_usedProducts)) { 
     if (is_null($requiredAttributeIds) 
      and is_null($this->getProduct($product)->getData($this->_configurableAttributes))) { 
      $this->getConfigurableAttributes($product); 
      Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__); 
      return $this->getProduct($product)->getData($this->_usedProducts); 
     } 

     $usedProducts = array(); 
     $collection = $this->getUsedProductCollection($product) 
      ->addAttributeToSelect('*') 
      ->addFieldToFilter('name', array('like' => '%'.$stock.'%')); 

     if (is_array($requiredAttributeIds)) { 
      foreach ($requiredAttributeIds as $attributeId) { 
       $attribute = $this->getAttributeById($attributeId, $product); 
       if (!is_null($attribute)) 
        $collection->addAttributeToFilter($attribute->getAttributeCode(), array('notnull'=>1)); 
      } 
     } 

     foreach ($collection as $item) { 
      $usedProducts[] = $item; 
     } 

     $this->getProduct($product)->setData($this->_usedProducts, $usedProducts); 
    } 
    Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__); 
    return $this->getProduct($product)->getData($this->_usedProducts); 
} 

public function getTable($product = false, $stock) 
{ 
    if (!$product) return false; 
     $childProducts = $this->getMatrixData(null, $product, $stock); 
     $x = array(); 
     $r = ''; 

      foreach ($childProducts as $children){ 
       $x[$children->getAttributeText('quantity')][$children->getAttributeText('size')] = array('id'=>$children->getId(), 'price'=>number_format($children->getPrice(),'2'), 'name'=>$children->getName()); 
      } 
     ksort($x); 
     $r .= '<table id="'.strtolower(str_replace(' ','-',$stock)).'" class="matrix"><tr><th></th>'; 

      foreach(array_keys(current($x)) as $size){ 
       $r .= '<th>'.$size.'</th>'; 
      } 
     $r .= '</tr>'; 

      foreach($x as $quantity => $data){ 
       $r .= '<tr><th>'.$quantity.'</th>'; 
        foreach($data as $item){ 
         $r .= '<td><a href="/checkout/cart/add?product='.$item[id].'" title="Add '.$item[name].' to basket">£'.$item[price].'</a></td>'; 
        } 
       $r .= '</tr>'; 
      } 
     $r .= '</table>'; 
     return $r; 
    } 

それがあるとテーブルが完全にロードするように、これは正常に動作します:

<div id="matrix-container"> 
    <?php $attributeSetName = Mage::getModel('eav/entity_attribute_set')->load($_product->getAttributeSetId())->getAttributeSetName(); ?> 
    <?php $stock = $_product->getResource()->getAttribute('stock'); ?> 
    <?php if($stock->usesSource()):?> 
    <?php $options = $stock->getSource()->getAllOptions(false); ?> 
     <?php foreach ($options as $k => $v):?> 
      <?php $options[$k] = $v['label']; ?> 
      <?php $stockQuery = $options[$k].' '.$attributeSetName; ?> 
      <?php echo Mage::getModel('catalog/product_type_configurable')->getTable($_product, $stockQuery); ?> 
     <?php endforeach;?> 
    <?php endif;?> 
</div> 

そして、ここでの機能:これは、これら2つの機能と、この呼び出しによって行われますすべてのテーブルをページロードして表示/非表示にするのではなく、ドロップダウン値をAJAXスクリプトにデータとして送信し、テーブルを再ロードする。私はAJAXで前にMagentoで試したことがありますが、何も問題はなく、誰かが私に問題を解決するために編集できるような現実的な例を与えることができるかどうか疑問に思いました。

私はすべてのコードとロジックを持っていることがわかりました。表示/非表示にjQueryではなくリロードできるようにAJAXで示しています。

乾杯。

+0

私はあなたの目標を知らないが、あなたはどのjQueryのデータ・テーブルを使用することができます

は、ここでの非常に簡単な例ですあなたが望むほとんどのものが利用可能です。 [jQuery DataTables](http://www.datatables.net/) –

+0

こんにちはOguz、それは正常に見えますが、私の問題はデータテーブル自体ではなく、うまくいきます(私のサンプルページを参照)。 MagentoからAJAXリクエストを送信する私が言っているように、これまでMagentoで簡単な変数を呼び出してメソッドエラーなどを取得していましたが、通常、必要なクラスがロードされていないようなことを指しています。それは以前の試みであった。 –

+0

パフォーマンス上の問題を解消するために必要なすべての値をロードし、選択してフィルタリングするのはどうですか? –

答えて

関連する問題