I am trying to merge these 2 line of code for an if statement. The purpose is to hide the attribute if Code1 is blank. Each one reports correct but when place together the code give errors. Thanks for the hint :)
Code1
<?php if ($_product->getAttributeText('tempi_consegna') != '') ?>
Code2
<p class="availability in-stock"><?php echo $this->__('Consegna:') ?>
<span>
<?php echo $_product->getAttributeText('tempi_consegna') ?>
</span>
</p>
They should be living friendly in magento product availability.
You can try as following:
<?php if ($_product->getAttributeText('tempi_consegna') != ''): ?>
<p class="availability in-stock"><?php echo $this->__('Consegna:') ?>
<span>
<?php echo $_product->getAttributeText('tempi_consegna') ?>
</span>
</p>
<?php endif; ?>
Related
I am not a great programmer but want to translate my Dutch attributes on the category overview page. Currently it's like this:
Current Dutch attribute names :
Now I would like to translate "Merk" for example in the German version "Marke". I coded it like this:
<div class="price-box">
<?php if ($_product->getAttributeText('merk') != ''): ?>
<p class="availability in-stock opties"
style="margin-top: 15px; margin-bottom:8px;">
<?php echo $this->__('■ Merk:') ?>
<span>
<?php echo $_product->getAttributeText('merk') ?>
</span>
</p>
<?php endif; ?>
<?php if ($_product->getAttributeText('supdoelgroep') != ''): ?>
<p class="availability in-stock opties"
style="margin-top: 8px; margin-bottom:8px;">
<?php echo $this->__('■ Voor:') ?>
<span>
<?php echo $_product->getAttributeText('supdoelgroep') ?>
</span>
</p>
<?php endif; ?>
Does anyone know the php codes so I can fill in the translation per storeview?
You need to used magento default translate functionality.
For This :
<?php echo $this->__('Merk') ?>
Add like:
app/locale/{lang_ISO}/Mage_Catalog.csv
add value in this csv file like,
"Merk","Marke"
This is the code that shows a Manufacturer Part Number on my product listing
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
what I would like to do is not show the MPN: Field on the product page if the $text_mpn field is blank, e.g if no part number is listed.
You can put an if statement around it. You can close the PHP code block after the if, put your code inbetween and open a new PHP code block to close it:
<?php if ($text_mpn != ''){ ?>
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
<?php };>
For blocks like this, it can be a bit messy and unclear to see where the block ends if you use normal curly braces, so you might consider the Alternative syntax for control structures for these cases:
<?php if ($text_mpn != ''):?>
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
<?php endif;>
try this:
<?php if($mpn != ""){ ?>
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
<?php } ?>
try this
<?php if(strlen($text_mpn) > 0) echo "<span class='p-rewards'>MPN:".$text_mpn."</span>".$mpn."</br>"; ?>
Case 1:
You can use empty() for check is variable is empty or not.
<?php if(empty($mpn)){ ?>
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
<?php } ?>
Case :2
You can simply use display:none if you wants to hide control.you can simply add attribute of style.
<div <?php if(empty($mpn))
{ echo 'style="display:none"';}
else {echo 'style="display:block"';}
?> >
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
</div>
<?php
$mpn = 'Ram Pukar';
$text_mpn = 'Hello ';
echo $text = !empty($mpn) ? '<span class="p-rewards">MPN: '.$text_mpn.'</span>'.$mpn.'<br />':null;
?>
Output:
MPN: Hello Ram Pukar
I would like to use a PHP echo as a condition inside a PHP if statement.
The aim is to have the list of blog articles written by John Doe, displayed on his biography page.
It worked when I directly wrote the author's name in the if condition:
<!-- current page: biography page -->
<div id="list_of_articles_by_John_Doe">
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == 'John Doe'): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
But I would like to automate the process, for each writer's biography page to have their own list of articles.
I tried to have as a condition the author of the current biography page ($page):
<!-- current page: biography page -->
<div id="automatic_list_of_articles">
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == $page->author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
but it makes another issue: it does not work because inside the foreach statement, $page->author() (condition in the if statement) does not echo the author once, but one time for each page('magazine')->children() as $article.
The condition if($article->author() == $page->author()) does not work in this case, as $page->author() is not strictly the writer's name.
I'm wondering how to call $page->author() to echo the writer's name only once, when inside the foreach statement.
What could be an option is to save all author within an array
// if article->author() isn't within the array
$authors[] == $article->author();
After that you could go as the following:
<?php foreach($authors as $author){ ?>
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == $author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
<?php } ?>
That should work, even if you must do 2 foreachs
<?php if( $article->author() == $page->author() ) { ?>
<p><?php echo $article->title(); ?></p>
<?php } ?>
should work, but you can also try
<?php
if( $article->author() == $page->author() ) {
echo "\n<p>", $article->title(), "</p>\n";
}
?>
which to me looks "cleaner"; but you'd have to have a look for missing whitespaces
I suggest trying to set it equal too a variable and then using that variable in the if statement.
<?php foreach(page('magazine')->children() as $article): ?>
<?php $condition = $page->author()?>
<?php if($article->author() == $condition ?>'): ?>
echo "\n<p>", $article->title(), "</p>\n";
<?php endif ?>
<?php endforeach ?>
I am not sure if my syntax is correct but i think it is something along them lines.
You cannot use echo in condition because it is special language construct that sends given contents to the output stream and it returns no value.
Are you sure you shouldn't have this?
<div id="automatic_list_of_articles">
<?php $page = page('magazine'); ?>
<?php foreach($page->children() as $article): ?>
<?php if($article->author() == $page->author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
I have reconstructed an approximation of what looks to be your data, and you can see it working at the link below. It correctly echo's multiple article titles.
Working example:
http://ideone.com/jvLVhF
In this example you can see the PHP as above works correctly, and it is likely a data issue (ie. you should perhaps be using $page and not calling a function in the foreach statement).
I'll get straight to the point. What is going on here, is I have a webstore, that has an inventory system sync'ed up with it. The issue at hand, is that we get backordered a lot, or have preorders. In the system, it will go to zero or negative numbers all the time, but we still want them to be able to order them.. just not necessarily see that we are -100 of such and such an item.
I currently have;
<?php if ($_product->isAvailable()): ?>
<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <?= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?> <span><?php echo $this->__('in stock') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability: ') ?> <span><? php echo $this->__('Call for Availability') ?></span></p>
<?php endif; ?>
This currently will show the inventory at whatever number it is, be it plus, minus, or at zero, which makes sense since there is no conversion to send it to out of stock if the number is =< 0. I am just not sure how I would go about mocking that up. So I come to you geniuses! Thanks for any and all help!
Configuration => Catalog => Inventory:
Display Out of Stock Products => Yes
Manage Stock => No
This should allow to sell products without managing remained products in stocks
Otherwise just replace with
<?php if ($_product->isAvailable()): ?>
<p class="availability in-stock"><?php echo $this->__('Availability:') ?>
<span>
<?php
$qty = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if ($qty<=0){echo $this->__('Call for Availability');}
else {echo $qty;} ?>
</span>
</p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><? php echo $this->__('Call for Availability') ?></span></p>
<?php endif; ?>
I am trying to show text content just with a PHP if condition but I have several errors and I don’t see where is the error could someone help me with this, here is the code:
<?php
if(
isset($_POST['send']) &&
!validateDiscp($_POST['Discp']) || !validateSize($_POST['Size'])
) : ?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])):?>
<li><strong>Discription:</strong>Discription need to be larger then 10!</li>
<?php endif?>
<?php if(!validateSize($_POST['Size'])):?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php endif ?>
</ul>
</div>
<?php elseif(isset($_POST['send'])):?>
<div id="error" class="valid">
<ul>
<li><strong>Congratulations!</strong> All fields are OK ;)</li>
</ul>
</div>
<?php endif ;?>
I would rewrite the whole outside block. Instead do:
<? if( isset($_POST['send'])&& !validateDiscp($_POST['Discp']) || !validateSize($_POST['Size']) ) { ?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])) { ?>
<li><strong>Discription:</strong> Discription need to be larger then 10!</li>
<?php } ?>
<?php if(!validateSize($_POST['Size'])) { ?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php } else {
$nothing = true;
?>
</ul>
</div>
<?php if( isset( $nothing ) and isset($_POST['send'] ) ) { ?>
<div id="error" class="valid">
<ul>
<li><strong>Congratulations!</strong> All fields are OK ;)</li>
</ul>
</div>
<? } ?>
I think the flaw in your logic ist hat you have an else statement that is dangling. Instead add a little logic to detect when the else case is hit and add your additional logic and your good to go.
All the endifs need to have ; after them. Also, I'm not sure if this is an actual error or just the code getting wrapped, but make sure your first if is all on one line.
after changing things it is working here is the code
<?php if(isset($_POST['send']) && !validateDiscp($_POST['Discp'])|| !validateSize($_POST['Size']) ):?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])):?>
<li><strong>Discription:</strong> Discription need to be larger then 10!</li>
<?php endif;?>
<?php if(!validateSize($_POST['Size'])):?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php endif; ?>
</ul>
</div>
<?php elseif(isset($_POST['send']) ):?>