Quiero hacer eco de una cadena en price.phtml
-
12-12-2019 - |
Pregunta
Quiero hacer eco de una cadena en mi price.html y estoy usando esta declaración if
<?php if($_product->getData('bogof')==1){
echo 'test';} ?>
pero no imprime nada. Sé que la declaración IF funciona ya que la uso en otros lugares de mi sitio web.Este es el contexto en el que estoy intentando usarlo.
<?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>
Básicamente, si el producto tiene un atributo bogof y está configurado en treu, entonces necesita imprimir la prueba.Pero no funciona y no estoy seguro de por qué, ya que funciona en otros archivos de mi sitio web.
cuando agrego $test = Mage::getSingleton("catalog/config")->getProductAttributes();
luego var_dump $test regresa
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" }
Y me dijeron que necesito agregar el atributo bogog a esta matriz, pero no sé cómo hacerlo.
Solución
Debe asegurarse de que la llamada al addAttributeToSelect()
El método contra la colección de productos es agregar su atributo.
->addAttributeToSelect('some_attribute', 'bogof')
o incluso simplemente usar *
para seleccionar todos los atributos (aunque es posible que no desee hacer esto en la práctica dependiendo de la cantidad de atributos que tenga):
->addAttributeToSelect('*')
Sugeriría mirar lo que se devuelve Mage::getSingleton("catalog/config")->getProductAttributes()
asegurarse bogof
aún no está incluido y, si no lo está, probablemente puedas agregarlo.Esto hará que los datos de atributos estén disponibles para el producto cargado desde la colección.