deseja ecoar uma string no price.phtml
-
12-12-2019 - |
Pergunta
Quero fazer eco de uma string em meu price.html e estou usando esta instrução if
<?php if($_product->getData('bogof')==1){
echo 'test';} ?>
mas não imprime nada, sei que a instrução IF funciona, pois a uso em outros lugares do meu site.Este é o contexto em que estou tentando usá-lo.
<?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>
Basicamente, se o produto tiver um atributo bogof e estiver definido como treu, será necessário imprimir o teste.Mas não está funcionando e não sei por que funciona em outros arquivos do meu site.
Quando eu adiciono $test = Mage::getSingleton("catalog/config")->getProductAttributes();
então var_dump $test ele retorna
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" }
E me disseram que preciso adicionar o atributo bogog a esse array, mas não sei como fazer isso?
Solução
Você precisa ter certeza de que a chamada para o addAttributeToSelect()
O método em relação à coleção de produtos é adicionar seu atributo.
->addAttributeToSelect('some_attribute', 'bogof')
ou até mesmo usar *
para selecionar todos os atributos (embora você possa não querer fazer isso na prática, dependendo do número de atributos que possui):
->addAttributeToSelect('*')
Eu sugeriria olhar o que é retornado de Mage::getSingleton("catalog/config")->getProductAttributes()
para ter a certeza bogof
ainda não está incluído e, se não estiver, você provavelmente poderá adicioná-lo.Isso disponibilizará os dados do atributo para o produto carregado da coleção.