2016-05-18 21 views
0

magento 2のWebサイトの製品ビューページにいくつかの属性を表示しようとしています。しかし、私はページにエコーする値を取得することができません。私はまた、価格の値とPHTMLファイルを経由してカスタムテキスト属性と表示/使用時に呼び出すようにしようとしています製品ビューページの属性をmagentoで表示する方法2

$block->getData('price') 

$block->getAttributeText('name') 

を使用して試してみました。

ヘルプを評価してください。あなたはあなたの条件に応じてコーディング以下をカスタマイズすることができ

<?php $_product = $block->getProduct(); 
echo $_product->getPrice(); 
echo $_product->getAttributeText('color'); 
?> 

答えて

0

はこれを試してみてください。カスタム商品属性(保証)を表示する場合は、まずファイルcatalog_product_view.xmlを編集し、次のコンテンツを更新する必要があります。このセクションは、product.info.mainコンテナ内に追加できます。ブロックをproduct.info.overviewブロックの隣に追加できます。したがって、短い説明属性の隣に表示されます。

<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.demo" template="product/view/demo.phtml" after="-"> 
<arguments> 

<argument name="at_call" xsi:type="string">getWarranty</argument> 

<argument name="at_code" xsi:type="string">warranty</argument> 

<argument name="css_class" xsi:type="string">warranty </argument> 

<argument name="at_label" xsi:type="string">warranty </argument> 

<argument name="add_attribute" xsi:type="string">itemprop="warranty "</argument> 

</arguments> 

</block> 

次の内容のmageno2root/vendor/magento/module-catalog/view/frontend/templates/product/viewの下に新しいファイルwarranty.phtmlを作成します。

<?php 

$_helper = $this->helper('Magento\Catalog\Helper\Output'); 

$_product = $block->getProduct(); 

$_code = $block->getAtCode(); 

$_className = $block->getCssClass(); 

$_attributeLabel = $block->getAtLabel(); 

$_attributeType = $block->getAtType(); 

$_attributeAddAttribute = $block->getAddAttribute(); 



if ($_attributeLabel && $_attributeLabel == 'default') { 

$_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel(); 

} 

$_attributeValue =$_product->getResource()->getAttribute($_code)->getFrontend()->getValue($_product); 

?> 

<?php if ($_attributeValue): ?> 

<div class="product attibute <?php echo $_className?>"> 

<?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php echo $_attributeLabel?></strong><?php endif; ?> 

<div class="value" <?php echo $_attributeAddAttribute;?>><?php echo $_attributeValue; ?></div> 

</div> 

<?php endif; ?> 

希望すると助かります。

0

:ありがとう

0
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($singleproductdata['entity_id']); 
     $attributes = $product->getAttributes(); 
     foreach ($attributes as $attribute) { 

       echo $attribute->getAttributeCode(); 
       echo $attribute->getFrontend()->getValue($product); 

     } 
関連する問題