When I echo my own variable to a div container it comes out as plaint text (unformatted). I don't understand why echoing a Magento variable comes out formatted but mine doesn't? Here's my code, in particular the <?php if(!isset($specialPrice)): { ?> section which I created. Here is the code:
<div class="product">
<a href="<?php echo $_item->getProductUrl() ?>"
title="<?php echo $this->escapeHtml($_item->getName()) ?>" class="product-image"><img
src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail') ?>"
alt="<?php echo $this->escapeHtml($_item->getName()) ?>"/></a>
<div class="product-details">
<p class="product-name">
<?php echo $this->escapeHtml($_item->getName()) ?>
</p>
<?php $specialPrice = $productToCheck->getData('special_price');
$orignalPrice = $productToCheck->getData('price');
?>
<?php if(!isset($specialPrice)): { ?>
<?php echo $product['price'] ?>
<?php } else: { ?>
<?php echo $specialPrice ?>
<?php } endif ?>
</div>
</div>
Echoing $product['price'] shows up with its CSS like this:
but if it enters the ELSE statement to display my variable it shows like this:
Does anyone know what could be going wrong?
$product['price'] returns you a unformatting price value.
Maybe you can call a block function, for example $block->getPrice() and in getPrice() you need to format the price by your custom preferences.
If you want to add styles to your price value then you need to use a magento tag class
Related
Firstly, I am a total php newby.
Secondly, below is the php header plus corresponding recursive commands for 2 photo lightboxes that are in the same html page.
Without the lines
getRecords() as $Title_row){ ?>
The page shows shows the first picture that is held in the external db table in the lightbox correctly.
Yet when I add the line below to add all the other entries in each table
getRecords() as $Title_row){ ?>
the page goes white and the browser html return is empty.
As I do not really understand what I am doing, I am stuck. Any suggestions would be very welcome.
<?php
$Title_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title_findCriterions = array('Order_web'=>'*',);
foreach($Title_findCriterions as $key=>$value) {
$Title_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title_find,'Title',50);
$Title_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title_result = $Title_find->execute();
if(FileMaker::isError($Title_result)) fmsTrapError($Title_result,"error.php");
fmsSetLastPage($Title_result,'Title',50);
$Title_row = current($Title_result->getRecords());
?>
<?php
$Title1_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title1_findCriterions = array('Order_web'=>'*',);
foreach($Title1_findCriterions as $key=>$value) {
$Title1_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title1_find,'Title',50);
$Title1_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title1_result = $Title1_find->execute();
if(FileMaker::isError($Title1_result)) fmsTrapError($Title1_result,"error.php");
fmsSetLastPage($Title1_result,'Title',50);
$Title1_row = current($Title1_result->getRecords());
?>
<!DOCTYPE html>
<!-- Lightbox Gallery -->
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<!-- Lightbox Gallery End-->
You just missed out the closing brackets :
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
have a phtml file riding the payment of the value of a product, the function responsible for it automatically puts on every page of the product installment conditions, but does not appear the payment terms on the homepage where I coloto one "carousel "for featured products.
Someone would have a hint of what I do?
Note 1: I use a AllPago the module to set the conditions only that I can not use the stand for the value that do not have access.
Note 2: according to the source code that assembles the installments for me (file name in magento to find looks like this: allpago_installments / productviewtable.phtml
<?php foreach ($this->getInstallments() as $installment): ?>
<?php $result = count($this->getInstallments()); ?>
<?php if($installment->getValue()==$result):?>
<div class="product-view-parcel">
<?php echo $installment->getValue() . ' x ' . $installment->getInstallment() . ' ' . $installment->getMessage(); ?>
</div>
<?php endif;?>
<?php endforeach; ?>
Note 3: a part of the home page code where I try to call the price and conditions (heeding the price appears correctly only the payment terms that do not):
<div id="ripplesslider" class="ripplesslider" style="height: 470px!important;">
<?php foreach ($_productCollection_slider as $_product): ?>
<div id="slide" style="text-align: center !important;height: 470px!important;"
class="latest-slider-item slide slider<?php echo $_product->getId() ?>">
<a href="<?php echo $_product->getProductUrl() ?>"
title="<?php echo $this->htmlEscape($_product->getName()) ?>">
<div style="height: 200px!important;">
<img onmouseover="mouseover(<?php echo $_product->getId() ?>)"
onmouseout="mouseout(<?php echo $_product->getId() ?>)"
style="width:<?php echo $t ?>px;
height:<?php echo $imageheight ?>px; "
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image'); ?>"
alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
</div>
</a>
<div class="desc-item">
<div class="carousel-name-product"> <?php echo $_product->getName() ?></div>
<div class="latest-price">
<?php if ($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php $this->getPriceHtml($_product, true) ?>
<?php echo '<span czlass="price">' . str_replace('R$','', $this->getPriceHtml($_product, true)) . '</span>'; ?>
</div>
</div>
</div>
<?php endforeach ?>
</div>
haha staff already got, I'll post here what I did to perhaps help others.
<div>
<?php echo '<span class="price">' . str_replace('R$','', $this->getPriceHtml($_product, true)) . '</span>'; ?>
<?php // object reference?>
<?php $reference = Mage::getStoreConfig('allpago/installments/active'); ?>
<?php//returns a new object. references ?>
<?php $installmentModel = Mage::getModel('installments/'.$reference); ?>
<?php //access the parameters to get the conditions have to function "getInstallmentHighest" to return the plots?>
<?php $installmentModel->setValue($_product->getFinalPrice()); ?>
<?php $installment = $installmentModel->getInstallmentHighest(); ?>
<span style="text-align: left;color: #A8A0A8;position: absolute;margin-top: -46px !important;margin-left: -78px !important;font-size: 12px;">
<?php echo $installment->getValue().' x '. $installment->getInstallment() . ' ' . $installment->getMessage(); ?>
</span>
</div>
I'm trying to make an if-else-statement which works by going if there is a link print it around the name.
I have the below code which is almost there. However, the link is being printed above the text ranther than being an actual link.
<?php if( the_sub_field('corporate_link') ){ ?>
<a href="<?php the_sub_field('corporate_link'); ?>"
target="_blank"
title="<?php the_field('corporate_name'); ?>"><?php the_field('corporate_name'); ?></a>
<?php } else { ?>
<?php the_sub_field('corporate_name'); ?>
<?php } ?>
Any thoughts on how to make it link instead of printing the link if it`s there?
So what im looking to acheive is if there is a link print this
Coprate Name
If there isn't a link it just shows the corporate name.
use get_sub_field('corporate_link') instead of the_sub_field('corporate_link')
<?php
$corporate_link = get_sub_field('corporate_link');
$corporate_name = get_sub_field('corporate_name');
if( $corporate_link != '' ){ ?>
<a href="<?php echo $corporate_link; ?>"
target="_blank"
title="<?php echo $corporate_name; ?>"><?php echo $corporate_name; ?></a>
<?php } else { ?>
<?php echo $corporate_name; ?>
<?php } ?>
use get_sub_field() and get_field() instead of the_sub_field() and the_field()
I'm editing a premium magento template right now (Hellodisplay) which has a featured product section on it's homepage. That section works by calling a specific category defined in a static block. My problem with this section is I couldn't show the special price of the products in any way. Althought the special product showed up on the product detail page. It also runs normal on the default template.
I've tried both function getSpecialProduct and getFinalProduct. GetSpecialProduct return nothing and GetFinalProduct return the normal price. I've also tried to use default theme price child html (price.phtml). It also doesn't works.
Then I check the print_r() output of $_product variable both on the homepage and also on the product page.I noticed the differences. Special array value exist only on the product pages's $_product variable. So how can I make this special price value appear on the homepage too?
This is my featured.phtml code
<?php
/**
* Product list template
*
* #see Mage_Catalog_Block_Product_List
*/
?>
<?php
$product_limit = 3;
$i = 1;
$_productCollection=$this->getLoadedProductCollection();
$cat_id = $this->category_id;
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'price', 'small_image', 'status'), 'inner')
->addCategoryFilter(Mage::getModel('catalog/category')->load($cat_id));
?>
<?php if(!$_productCollection->count()): ?>
<div class="note-msg">
<?php echo $this->__('There are no products matching the selection. Please provide a category ID.') ?>
</div>
<?php else: ?>
<ul class="frontgrid">
<?php $_collectionSize = $_productCollection->count() ?>
<?php foreach ($_productCollection as $_product): ?>
<?php if($i >= $product_limit+1){
break;
} else{
$a = $i % 3;
$i++;
} ?>
<li class="<?php echo "col".$a; ?>">
<a class="imglink" href="<?php echo $_product->getProductUrl() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200, 200); ?>" width="200" height="200" alt="<?php echo $this->htmlEscape($_product->getName()); ?>" />
</a>
<h4><?php echo $this->htmlEscape($_product->getName()); ?></h4>
<div class="boxbar">
<span class="oldprice">
<?php if($this->htmlEscape($_product->getSpecialPrice())){ ?>
€ <?php echo number_format($this->htmlEscape($_product->getPrice()), 2) ?>
<? } ?>
</span>
<span class="price">
<?php if($this->htmlEscape($_product->getSpecialPrice())){ ?>
€ <?php echo number_format($this->htmlEscape($_product->getSpecialPrice()), 2) ?><br/>
<? } else { ?>
€ <?php echo number_format($this->htmlEscape($_product->getPrice()), 2) ?>
<? } ?>
</span>
<a class="moreinfo" href="<?php echo $_product->getProductUrl() ?>">Meer Info »</a>
</div>
</li>
<?php endforeach ?>
</ul>
<?php endif; ?>
Thanks before :)
You have to add "special_price", "special_from_date" and "special_to_date" on addAttributeToSelect array.
I'm trying to output an image with SimpleXML, but the image tag doesn't appear in the source code.
Can anyone help me outpout this image:
Here's my XML and code:
<?php foreach($xml->Event as $event) { ?>
<li>
<a href="<?php echo $event->link; ?>">
<?php if ($event->Media['url'] == !null) { ?>
<img src="<?php echo $event->Media['url'];?>" alt="<?php echo $event->title;?> thumbnail" />
<?php } ?>
<h3><?php echo $event->title; ?></h3>
<p><strong><?php echo $event->beginDate; ?> at <?php echo $event->beginTime; ?></strong></p>
<p><?php echo $event->location; ?></p>
</a>
</li>
<?php } ?>
Your issue is here:
<?php if ($event->Media['url'] == !null) { ?>
<img src="<?php echo $event->Media['url'];?>" alt="<?php echo $event->title;?> thumbnail" />
<?php } ?>
You're trying to access url as though it were an attribute, you need to access it as a child element by using ->url instead.
<?php if ($event->Media->url != null) { ?>
<img src="<?php echo $event->Media->url;?>" alt="<?php echo $event->title;?> thumbnail" />
<?php } ?>
EDIT: By the way, == !null works as you expect, but != null is a bit friendlier and less confusing
Your if statement is incorrect. It should be:
if ($event->Media['url'] != null)