カテゴリリストページに構成可能な製品オプションを表示する方法
-
16-10-2019 - |
質問
カテゴリリストページに構成可能な製品オプションの表示を確認する方法は?
解決
カテゴリにすべての販売可能なオプションを表示するためだけに移動します .../app/design/frontend/[package]/[theme]/template/catalog/product/list.phtml
そして中に置きます foreach ($_productCollection as $_product)
このようなもの:
<?php if($_product->isConfigurable()): ?>
//get attributes
<?php $attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
<?php if(count($attributes)): ?>
<ul>
<?php foreach($attributes as $att): ?>
<?php $pAtt=$att->getProductAttribute();
//get the child products
$allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
$frontValues =array() ?>
<li><?php echo $pAtt->getFrontendLabel() ?>
<ul>
<?php foreach($allProducts as $p): ?>
//check stock, status, ...
//do not show unsaleable options
<?php if(!$p->isSaleable()) continue; ?>
<?php $out=$p->getAttributeText($pAtt->getName()); ?>
<?php $frontValues[$out]=$out; ?>
<?php endforeach ?>
<li><?php echo implode('</li><li>', $frontValues) ?></li>
</ul>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
<?php endif ?>
おそらくあなたはいくつかのCSSクラスをに追加したいです <ul>
と <li>
タグ。
これにより、お店のパフォーマンスが向上しません!
この投稿に触発されました
http://www.magentocommerce.com/boards/viewthread/73926/#t437146
他のヒント
のようなものを使用できます if ($_product->getTypeId() == 'configurable')
製品ループの内側。
これを試してみてください。Magentoの製品リストページに利用可能な構成可能な製品オプションを表示
これは、各製品に多くのオプションがある可能性があるため、かなりのサーバーリソースを取り上げることができます。最良の方法は、Ajaxを使用して、求められたときにすべてのオプションのみをロードすることです。最初に色をロードするこの拡張機能を見つけました。次に、マウスをマウスすると、すべての製品オプションが得られます。
http://www.consofas.com/plugins/options-quickview-for-configurable-products-in-magento/
これを一度試してみてください
<?php $ptype = $_product->getTypeId();?>
<?php
if($ptype=='configurable'): ?>
<!--get attributes-->
<?php
$attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
<?php
if(count($attributes)): ?>
<?php
foreach($attributes as $att): ?>
<?php
$pAtt=$att->getProductAttribute();
//get the child products
$allProducts = $_product->getTypeInstance(true)->getUsedProducts($_product,null);
$frontValues =array();
foreach($allProducts as $p):
if($p->isSaleable()):
$attributeExist =$_product->getResource()->getAttribute($pAtt->getName());
?>
<input type="hidden" name="super_attribute[<?php echo $pAtt->getAttributeId() ?>]" value="<?php echo $attributeExist->getSource()->getOptionId($p->getAttributeText($pAtt->getName()));?>">
<?php
break;
endif;
endforeach;
endforeach;
endif;
?>
<?php
endif;
?>
次のリンクが役立つかもしれません。
http://hkpatel201.blogspot.in/2012/09/get-product-custom-option-in-list-page.html
コードを通過します
ありがとう