2
我想顯示2個自定義產品屬性,我使用條件語句在前端的管理員中創建。第一個是Availability
,第二個是shipping_rate
。Magento 2 phtml文件中的條件語句
我已經編輯地處defauproduct頁面模板:
/vendor/magento/module-catalog/view/frontend/templates/product/view/type/default.phtml
這樣:
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php /* @var $block \Magento\Catalog\Block\Product\View\AbstractView */?>
<?php $_product = $block->getProduct() ?>
<?php if ($block->displayProductStockStatus()): ?>
<?php if ($_product->isAvailable()): ?>
<div class="stock available" title="<?php /* @escapeNotVerified */ echo __('Availability') ?>">
<span><?php /* @escapeNotVerified */ echo __('In stock') ?></span>
</div>
<span class="estimated-delivery">
<?php /* @escapeNotVerified */ if ($_product->getResource()->getAttribute('availability')->getValue($_product) != '0'): ?>
Livraison estimée dans <?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('availability')->getFrontend()->getValue($_product); ?> jour(s)</span>
<?php endif; ?>
<span>Livraison à partir de <?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('shipping_rate')->getFrontend()->getValue($_product); ?> €</span>
<?php else: ?>
<div class="stock unavailable" title="<?php /* @escapeNotVerified */ echo __('Availability') ?>">
<span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
我的問題是: 當可用性EQUA l到0,我想展示一些東西,當它不是0時,還有其他東西。這是一個經典的條件聲明,但我沒有成功:S
這是我做的,它沒有工作。
<span class="estimated-delivery">
<?php /* @escapeNotVerified */ if ($_product->getResource()->getAttribute('availability')->getValue($_product) != '0'): ?>
Livraison estimée dans <?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('availability')->getFrontend()->getValue($_product); ?> jour(s)</span>
<?php else ?>
Disponibilité: <strong>En Stock</strong> </span>
<?php endif; ?>
有人可以幫我寫這個條件語句嗎?
感謝