I am doing a magento customization site ,I need to add some additional information about the product to cart page, checkout page . I am new to magento please help how can i do this.
I tried this code in app\design\frontend\base\default\template\checkout\cart\item\default.phtml
$_product =$_item->getProductId();
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<div class="availability in-stock"><b>Compatible with : </b><div class="button2" style="color:#77C25A;"><?php echo $_additional['computer_manufacturers']['value']; echo " | "; echo $_additional['model_type']['value']; echo " | "; echo $_additional['model_version']['value'] ; ?> </div></div>
<?php endif;?>
Hi you can try the following:
$product = Mage::getModel("Catalog/Product")->load($_item->getProduct()->getId());
//echo sprintf("<pre>%s</pre>",print_r($product->getData(),true));
echo $product->getColor(); //shows the key 3
echo $product->getData('color'); //shows the key 3
echo $product->getAttributeText('color'); //shows the text blue
Make the attributes available in frontend:
On manage attribute page:
Allow HTML Tags on Frontend
Visible on Product View Page on Front-end
Remove the comment on the sprintf to see thats in there. When you have a _ in the key you should use CamelCase notation so the_color will become getTheColor().
Hope it helps !
Related
I have a text that I want to dispay as a description on every single product page and I want to echo the product name in the fields.
Example: ''Buy this (product name) from our store. This is the best (product name) in the industry. By using this (product name) you save more.''
I used the epho function but it seems not to work properly.
<? echo woocommerce_template_single_title(); ?>
Could some one please help me with that issue, it will be verry appreciated
P.S.: I use WooCommerce and Wordpress
you should use <?php ?>
<?php echo woocommerce_template_single_title(); ?>
or
<?= woocommerce_template_single_title(); ?>
Use:
<?php
$tittle = woocommerce_template_single_title();
echo $tittle;
?>
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 was looking for a way to display the "estimated delivery" of a product by using the attribute 'delivery' I've made.
So far I've managed to put together this:
<?php $delivery= Mage::getSingleton('catalog/product')->load($this->getProduct()->getId())->getAttributeText('Delivery'); ?>
<?php if(isset($delivery)){
echo $delivery;
}
?>
I have added this piece to:
template/checkout/cart/item/default.phtml - between line 38/39 (Magento Version 1.6.2)
Here is the default.phtml from line 35-49 with the code added to the h2 tag:
<h2 class="product-name">
<?php $_item = $this->getItem()?>
<?// Delivery - Script ?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php $delivery= Mage::getSingleton('catalog/product')->load($this->getProduct()->getId())->getAttributeText('Delivery'); ?>
<?php if(isset($delivery)){
echo $delivery;
}
?>
<?php if ($this->hasProductUrl()):?>
<?php echo $this->htmlEscape($this->getProductName()) ?>
<?php else: ?>
<?php echo $this->htmlEscape($this->getProductName()) ?>
<?php endif; ?>
</h2>
The problem is, the first product added to cart is being skipped, it's always showing the attribute as not set, but the second, third and rest of the products added to cart, works great, showing their est. delivery date just fine.
From here, I'm unsure how to proceed?
Use of singleton will result in same object being called repeatedly so previous object data will get overwritten.
Once you changed from singleton to getModel you have an instance for each product so no over writing on same instance.
After some Google'ing I found this, which seems to work - But I still cannot see why, and what the big difference is, if anyone would like to clarify it, I would be very happy.
This is the working solution, it's so simple, yet I don't understand:
<?php
$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
echo $custom->getAttributeText('delivery');
?>
This does not skip the first product?
app/design/frontend/{YOURTEMPLATE}/default/template/checkout/cart/item/default.phtml
Past this code:
<?php $_item = $this->getItem(); ?>
<?php $_product = $_item->getProduct()->load(); ?>
<?php $_product->get{YOUR ATTRIBUT HERE}(); ?>
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;?>
hey guys, having an issue with magento which i just cant seem to find a solution to.
i have tried many ways of getting a configurable products attributes (simple products) and listing them, now i have them listing from 2 ways but the way im working with is below
$confAttributes = #$_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
$sizes = array();
foreach($confAttributes AS $atts){
//print '';//'<pre style="display:none;">'.print_r($atts).'</pre>';
if($atts['label'] == 'Size'){
foreach($atts['values'] AS $val){
$sizes[] = $val['store_label'];
}
}
}
my only problem with this now is i need to only pull back the size attributes which are in stock - looked through mage files to find solution but just cant see anything - the result i need is done in config product php file but i cant access it from in the code where i need to list the size attribute.
any help would be great, thanks!
Solution:
You can get easily all configurable(product) details page information on any other PHTML file by using following code:
e.g.: in my case i'm getting details on catalog/product/list.phtml.
<script src="<?php echo Mage::getBaseUrl('js') ?>varien/configurable.js" type="text/javascript"></script>
<?php
$temp = new Mage_Catalog_Block_Product_View_Type_Configurable();
$temp->setData('product', $_product);
$_attributes = Mage::helper('core')->decorateArray($temp->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<?php foreach($_attributes as $_attribute): ?>
<?php
$prices = $_attribute->getPrices();
foreach($prices as $price) {
echo $price['pricing_value'] . "<br/>";
}
?>
<?php endforeach; ?>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $temp->getJsonConfig() ?>);
</script>
<?php endif;?>
Thanks,
found the solution, i had to use the above what i had already coded and use assosicated products for the size and then check the stock levels and put them into an array and check the stock when building my attribute list - works great - anyone else have a better solution please share :D thanks