I am using Magento eCommerce and I have modified my header.phtml via the Blank template. Code, this is my code but it shows blank.
<?php $cartQty = $this->getSummaryCount() ?>
<?php if ($cartQty>0): ?>
<?php if ($cartQty==1): ?>
<?php echo $this->__('<a class="cartgo" href="%s">(1 ITEM)</a>', $this->getUrl('checkout/cart')) ?>
<?php else: ?>
<?php echo $this->__('<a class="cartgo" href="%s">(%s ITEMS)</a>', $this->getUrl('checkout/cart')) ?>
<?php endif ?>
<?php endif ?>
There was an answer to a link before by someone called SUHUR I think, I was going to reward him with the answer but it seems he deleted his own post?
He linked to this: http://nothingtopost.wordpress.com/tag/how-to-get-total-cart-item-in-magento/
I modified my code and this works now on .phtml files.
<?php
$count = $this->helper('checkout/cart')->getSummaryCount(); //get total items in cart
$total = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price
if($count==0)
{
echo $this->__('(0 ITEMS)',$count);
}
if($count==1)
{
echo $this->__('(1 ITEM)',$count);
}
if($count>1)
{
echo $this->__('(%s ITMES)',$count);
}
echo $this->__('', $this->helper('core')->formatPrice($total, false));
?>
<?php
$cartTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
$cartItemsCount = Mage::helper('checkout/cart')->getCart()->getItemsCount();
$cartSuffix = ($cartItemsCount != 1) ? 's' : '';
echo '<a class="cartgo" href="'.$this->getUrl('checkout/cart').'">
<strong>'.$this->__('Your basket').'</strong><br />'.
$this->__('(%s) Item%s', $cartItemsCount, $cartSuffix).
'<span>[$'.$this->helper('core')->formatPrice($cartTotal, false).']</span>
</a>';
?>
Output:
Your basket
3 Items [$32.5]
<?php
$_cartQty = Mage::getSingleton('checkout/cart')->getItemsCount();
echo $_cartQty;
?>
thats all you need for 1.7 if your already running the mage:app which you can't do anything without really.
furthermore, this only shows "item" count, not quantity.
Use the helper object to get the current cart object, and then count the number of items in the cart object.
echo Mage::helper('checkout/cart')->getCart()->getItemsCount();
More from http://www.douglasradburn.co.uk/how-to-get-number-of-cart-items-in-magento/
You can find your cart template here:
YOURSITE/app/design/frontend/YOURTHEME/default/template/checkout/cart/minicart.phtml
Within a span with the class of .count you'll see this snippet:
<span class="count"><?php echo $_cartQty; ?></span>
Replace it with this snippet and you'll get the grand total displayed instead:
<?php echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); ?>
When linking to a cart, you should really use Mage::helper('checkout/cart')->getCartUrl(). The example given would not work if your site is hosted in a sub-domain.
<?php
$count = $this->helper('checkout/cart')->getSummaryCount(); //get total items in cart
$total = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price
if($count==0)
{
echo $this->__('(0 ITEMS)',$count);
}
if($count==1)
{
echo $this->__('(1 ITEM)',$count);
}
if($count>1)
{
echo $this->__('(%s ITMES)',$count);
}
echo $this->__('', $this->helper('core')->formatPrice($total, false));
?>
this works for me thanx...
Use the below code in phtml file to get the no of items in cart.
<?php $helper = $this->helper('\Magento\Checkout\Helper\Cart');
$noCartItems= $helper->getSummaryCount();
echo $noCartItems;?>
Related
I have 2 variables in phtml and want to make them a link.
<?php
$_reviewCount = $_ratingSummary->getReviewsCount();
$_reviewUrl=$_product->getRequestPath().'#reviews';
<!--Here if review count is 1 i want to show as "Review" else "Reviews" -->
<?php echo $_reviewCount ?>
<?php echo "<a href='".$_reviewUrl."'>Review</a>" ?>
<?php ($_reviewCount == 1 ) ? __('Review') : __('Reviews') ?>
But the above shows only keyword 'review' in lowercase .
Just rewrite your code to first define the singular or plural form and then echo it:
<?php
if($reviewCount==1){$text='Review';}else{$text='Reviews';}
echo "$_reviewCount $text";
?>
BTW i'd change the if condition to >1 because your code echoes Reviews if the count of reviews is 0.
<?php
if($_reviewCount>1){$text='Reviews';}else{$text='Review';}
echo "$_reviewCount $text";
?>
I have a link that passes variable to another page but I want to display that link only on some condition so how to place it inside php code.
Product
<?php
echo 'Product';
?>
This doesn't work.
Simply, put your anchor link in if condition:
<?php
if (YOUR_CONDITION_HERE) {
echo 'Product';
}
?>
OR
<?php
if (YOUR_CONDITION_HERE) {
?>
Product
<?php
}
?>
Above condition will display your link only when your condition is TRUE.
Otherwise, it will hide.
Your second line is incorrect why are you opening your php tags again while you're in a echo ?
Please try the following :
<?php
echo 'Product';
?>
Your echo field should be.
Product
<?php
echo 'Product';
?>
You dont have to print echo inside3 echo so u hv to do this way!
<?php
echo 'Product';
?>
Firstly I would like to apologise if this question has been answered somewhere else but I am unable to find what I am looking for as I am new to PHP and assume I need this to solve my problem.
I have built a website and am using Mals-e shopping cart. I have everything up and running but I would like to show how many products are still in stock under the product description and if there are no items in stock. For example:
Available stock: 2
or
Sold Out
I have read that I need a text file with product name, price and quantity, a PHP file to read and rewrite the quantity available and out put the results on the product page and a mypage.php page but I really don't know where to start. I've spent days trying to sort this out.
I have Mysql database with some items in table called (items) with available quantity but don't know how to go about sorting it out. Any help would be most appreciated.
Thank you.
Without seeing the actual code you're using to display the product, it's hard to say buy all you should need is something like:
<?php
// get the product and stock level
if($product->numberInStock > 0) {
echo 'Available: ' . $product->numberInStock;
} else {
echo 'Out of stock';
}
If you're editing a phtml type template (HTML with embedded PHP), you might display it like:
<? if($product->numberInStock > 0): ?>
<p>Available: <?= $product->numberInStock; ?></p>
<? else ?>
<p>Out of stock</p>
<? endif; ?>
Had same issue, found out following.
Inside your catalog/product type template you can use this:
<?php
$_product = $this->getProduct();
$_qty = $_product->getStockItem()->getQty();
?>
<p>
<?php if($_qty > 0): ?>
Available: <?php echo $_qty; ?>
<?php else: ?>
Out of stock
<?php endif; ?>
</p>
session_start($_POST['quantity']);
if(isset($_POST['quantity']))
{
$postedquantity=$_POST['quantity'];
$productQuantity="20";
if($postedquantity<$productQuantity){
echo "In stock";
echo "<br/>";
}
$productQuantity=$productQuantity-$postedquantity;
echo $productQuantity."Remaining";
}
You can even do like this,storing quantity value in session and everytime it's posted it will check whether it is in stock or not and it will show how much quantity is remaining.
I need a code that pulls out the listings count for a product in order to have them in the navigation. I am trying to get the product and listing number in the navigation (if there is any), but I don't want to display something if the listings count is equals to 0.
Here follows my code:
<?php if($listingsCount = getListingsCount(0,0,2,2,1,86) > 0): ?>
Bakery
<?php echo $listingsCount['totalRecords'] ?>.
<?php else: ?>
It should be
if ( ($listingsCount = getListingsCount(0,0,2,2,1,86)) > 0)
In this case you the assignment is done first and is then compared to 0. So $listingCount contains the real count.
The way you did it, the comparison is done first and the return value (true/false) is assigned to $listingCount.
Nevertheless. If you never reach the else-part, maybe something in your method getListingsCount() is broken.
Try this:
<?php if (($listingsCount = getListingsCount(0,0,2,2,1,86)) > 0) { ?>
Bakery
<?php echo $listingsCount['totalRecords']; ?>
<?php } else { ?>
Other text
<?php }?>
Thanks guys for your answers. managed to get it working with this...
<?php
$listingsCount = getListingsCount(0,0,2,2,1,86);
if($listingsCount['totalRecords'] > 0):
?>
<dd>
Bakery
[<?php echo $listingsCount['totalRecords'] ?>]
</dd>
<?php endif; ?>
How do you when using custom fields in Wordpress echo just the first value using foreach?
Currently the code is:
<?php for(get_field('venue_event') as $post_object): ?>
<?php echo get_the_title($post_object) ?>
<?php endforeach; ?>
This takes the field from the wordpress page (the field is a link to another page), creates a link to that page using get_permalink but when I want to echo the page title it does it, but then it also echos all other values that are not needed.
If you just want the execute the first iteration of the loop, try this:
<?php foreach(get_field('venue_event') as $post_object): ?>
<?php echo get_the_title($post_object) ?>
<?php break; ?>
<?php endforeach; ?>
Wouldn't it then be easier just to use the first element of the returned array? Maybe Wordpress offers other filters that return the the page's title only.
you can just add
$counter = 0;
<?php for(get_field('venue_event') as $post_object): ?>
$counter++;
if($counter == 1)
{
<?php echo get_the_title($post_object) ?>
}
<?php endforeach; ?>