хочу отобразить строку в файле Price.phtml
-
12-12-2019 - |
Вопрос
Я хочу отобразить строку в моем Price.html, и я использую этот оператор if
<?php if($_product->getData('bogof')==1){
echo 'test';} ?>
но он ничего не печатает, я знаю, что оператор IF работает, поскольку я использую его в других местах своего веб-сайта.Это контекст, в котором я пытаюсь его использовать.
<?php $this->setProduct(
Mage::getModel("catalog/product")->getCollection()
->addAttributeToSelect(Mage::getSingleton("catalog/config")->getProductAttributes())
->addAttributeToFilter("entity_id", $this->getProduct()->getId())
->setPage(1, 1)
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->load()
->getFirstItem()
);?>
<?php
$_coreHelper = $this->helper('core');
$_weeeHelper = $this->helper('weee');
$_taxHelper = $this->helper('tax');
/* @var $_coreHelper Mage_Core_Helper_Data */
/* @var $_weeeHelper Mage_Weee_Helper_Data */
/* @var $_taxHelper Mage_Tax_Helper_Data */
$_product = $this->getProduct();
$_storeId = $_product->getStoreId();
$_store = $_product->getStore();
$_id = $_product->getId();
$_weeeSeparator = '';
$_simplePricesTax = ($_taxHelper->displayPriceIncludingTax() || $_taxHelper->displayBothPrices());
$_minimalPriceValue = $_product->getMinimalPrice();
$_minimalPriceValue = $_store->roundPrice($_store->convertPrice($_minimalPriceValue));
$_minimalPrice = $_taxHelper->getPrice($_product, $_minimalPriceValue);
$_convertedFinalPrice = $_store->roundPrice($_store->convertPrice($_product->getFinalPrice()));
$_specialPriceStoreLabel = $this->getProductAttribute('special_price')->getStoreLabel();
?>
<span class="price-excluding-tax" >
<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php if ($_finalPrice == $_price): ?>
<?php echo $_coreHelper->formatPrice($_price, false) ?>
<?php else: ?>
<?php echo $_coreHelper->formatPrice($_finalPrice, false) ?>
<?php endif; ?>
</span>
<?php if($_product->getData('bogof')==1){
echo 'test';} ?>
<span class="label"><?php echo $this->helper('tax')->__('Excl. VAT') ?></span>
</span>
По сути, если продукт имеет атрибут bogof и для него установлено значение treu, необходимо распечатать тест.Но он не работает, и я не уверен, почему, поскольку он работает в других файлах на моем веб-сайте.
Когда я добавляю $test = Mage::getSingleton("catalog/config")->getProductAttributes();
затем var_dump $test возвращает результат
array(31) { [0]=> string(4) "name" [1]=> string(5) "price" [2]=> string(11) "small_image" [3]=> string(6) "status" [4]=> string(12) "tax_class_id" [5]=> string(7) "url_key" [6]=> string(9) "thumbnail" [7]=> string(17) "short_description" [8]=> string(13) "special_price" [9]=> string(17) "special_from_date" [10]=> string(15) "special_to_date" [11]=> string(14) "news_from_date" [12]=> string(12) "news_to_date" [13]=> string(16) "required_options" [14]=> string(10) "price_type" [15]=> string(11) "weight_type" [16]=> string(10) "price_view" [17]=> string(13) "shipment_type" [18]=> string(11) "image_label" [19]=> string(17) "small_image_label" [20]=> string(15) "thumbnail_label" [21]=> string(26) "links_purchased_separately" [22]=> string(11) "links_exist" [23]=> string(11) "is_imported" [24]=> string(12) "msrp_enabled" [25]=> string(30) "msrp_display_actual_price_type" [26]=> string(4) "msrp" [27]=> string(21) "c2c_paper_roll_holder" [28]=> string(10) "short_name" [29]=> string(15) "c2c_foot_switch" [30]=> string(9) "split_leg" }
И мне сказали, что мне нужно добавить атрибут bogog в этот массив, но я не знаю, как это сделать?
Решение
Вам необходимо убедиться, что вызов на addAttributeToSelect()
Метод против коллекции продуктов — добавление вашего атрибута.
->addAttributeToSelect('some_attribute', 'bogof')
или даже просто использовать *
чтобы выбрать все атрибуты (хотя на практике вы можете не захотеть этого делать, в зависимости от количества имеющихся у вас атрибутов):
->addAttributeToSelect('*')
Я бы предложил посмотреть, что возвращается из Mage::getSingleton("catalog/config")->getProductAttributes()
Чтобы убедиться bogof
еще не включен, и если это не так, вы, вероятно, можете просто добавить его.Это сделает данные атрибутов доступными для продукта, загруженного из коллекции.