문제

저의 Price.html에서 문자열을 recho recholy

        <?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 $ 테스트 를 반환합니다.

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()가 아직 포함되어 있지 않은지 확인하고 추가 할 수있는 경우에는 컬렉션에서로드 된 제품에 사용할 수있는 속성 데이터를 만들 수 있습니다..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top