Nobody that can help me? (update 17-02)
Basicly what I need it the following.
Get the qty of stock of a product
Show qty number X
When negative number show 0
When it's > 0 show image X
When it's < 0 show image Y
Old info
In magento I am showing the stock qty with the actual numbers.
When the number is lower then 0 he always shows 0.
What I now want to do is add an image to both conditions.
For example when the qty is > 0 show a green image and when the qty = 0 then show a red image. Anybody knows how to do this?
<div class="qty-amount2">
<?php //echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>
<?php $_op_voorraad = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if($_op_voorraad < 0){
$_op_voorraad = 0;
}
echo $_op_voorraad; ?><span><?php echo $this->__(' op voorraad') ?></span>
Ok got this fixed by hiring a developer but will share it
?>
<?php /* #var $this Mage_Catalog_Block_Product_View_Abstract */?>
<?php $_product = $this->getProduct() ?>
<?php if($_product->isSaleable()): ?>
<?php $_op_voorraad = (int) Mage::getModel('cataloginventory/stock_item')- >loadByProduct($_product)->getQty();?>
<?php if($_op_voorraad > 0): ?>
<div class="qty-amount2"><img style="float: left;" src="image_path" alt="">
<?php echo $_op_voorraad; ?><span><?php echo $this->__(' op voorraad') ?></span>
</div>
<?php else: ?>
<?php $_op_voorraad = 0;?>
<div class=" qty-amount2 geen"><img src="image_path" alt="">
<?php echo $_op_voorraad; ?><span><?php echo $this->__(' op voorraad') ?></span>
</div>
<?php endif;?>
<?php else: ?>
<div class="geen"><img src="image_path" alt="">
<p><?php echo $this->__('Availability: Out of stock.') ?></p></div>
<?php endif; ?><br>
<?php echo $this->getPriceHtml($_product) ?>
<?php
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if ($_product->isAvailable()):
if(intval($stock)>0){
//green image code
}else{
//red image code
}
endif;
?>
You don't need to know the stock quantity.
If the item is in Out of Stock the isSaleable() method return 'false'. You can use this method.
For Example:
<?php if($_product->isSaleable()): ?>
<img src="[linkimage1]" width="135" height="135" alt="" />
<?php else: ?>
<img src="[linkimage2]" width="135" height="135" alt="" />
<?php endif; ?>
Remember to enable the Out of Stock visibility on frontend:
from admin:System->Catalog\Inventory->Stock Options->Display Out of Stock Products ('Yes')
Reindex all.
Related
I'm working with Magento EE v1.14 and i'm looking for a solution for when a user is viewing a product page to then drop swatches of related product colors if they are out of stock.
Screenshot: Highlighted out of stock related product color
Screenshot of HTML
PHP + HTML code:
<?php
$_base_product = $this->getProduct();
$base_product = Mage::getModel('catalog/product')->load($_base_product->getId());
$base_product_id = $base_product->getId();
$base_name = $base_product->getName();
$base_url = Mage::getBaseUrl();
$product_colors = Mage::getModel('catalog/product')->getCollection();
$product_colors->addAttributeToFilter('status',1); // 1 or 2
$product_colors->addAttributeToFilter('visibility',4); // 1.2.3.4
$product_colors->addAttributeToFilter('name', array('eq' => $base_name));
$product_colors->addAttributeToFilter('sku', array('neq' => $base_product->getSku()));
$product_colors_ids = $product_colors->getAllIds(); // get all products from the category
sort($product_colors_ids);
?>
<?php if(count($product_colors_ids) > 0) : ?>
<div id="product-color-options-wrapper">
<div id="product-color-options-container">
<label><?php echo $this->__('Color') ?> / <span style="font-weight: normal;"><?php echo $base_product->getAttributeText('color'); ?></span></label>
<div id="color-options-wrapper">
<?php $_swatch_img = $base_product->getMediaGalleryImages(false)->getItemByColumnValue('label', 'swatch') ?>
<?php if($_swatch_img) : ?>
<div class="current-product-wash-wrapper wash-wrapper">
<div class="current-product-wash-container wash-container">
<img src="<?php echo $this->helper('catalog/image')->init($base_product, 'small_image', $_swatch_img->getFile())->resize(33,30) ?>" alt="" title="<?php echo $base_product->getAttributeText('color') ?>" />
</div>
</div>
<?php else : ?>
<!-- <span><?php echo $base_product->getColor() ?></span> -->
<?php endif ?>
<?php foreach($product_colors_ids as $prod_id) : ?>
<?php $_sister_product = Mage::getModel('catalog/product')->load($prod_id) ?>
<?php
$_sister_prod_imgs = $_sister_product->getMediaGallery('images');
foreach($_sister_prod_imgs as $_sister_prod_img):
if($_sister_prod_img['label'] == 'swatch'):
$_swatch_img = $_sister_prod_img['file'];
endif;
endforeach;
?>
<?php if($_swatch_img): ?>
<div class="sister-product-wrapper wash-wrapper">
<div class="sister-product-container wash-container">
<a href="<?php echo $base_url ?><?php echo $_sister_product->getUrlKey() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_sister_product, 'small_image', $_swatch_img)->resize(33,30); ?>" alt="" title="<?php echo $_sister_product->getAttributeText('color') ?>">
</a>
</div>
</div>
<?php endif; ?>
<?php endforeach ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php endif ?>
Any help would be appreciated! :D
**Solution:**Added an if statement to check for stock availability using the isAvailable() function, shown in screenshot.
Link to screenshot: https://gyazo.com/abf07ba0373877836571858ee129cc22
I have been fixing this store, based on magento. The main problem of this is that Some of the products display on the store view has incorrect size (which is attribute)
If you have a look at the picture, on the grid view (list.phtml) the size is US 16/ UK 18 / EUR 48 while on the single view page (view.phtml) it is US 6/ UK 8/ EUR 38.
Have a look at this link
http://www.sequinqueen.com/shop/in-stock.html
I have gone through the code in the view.phtml and appear that the code request the attribute value correctly according to the code below
<?php
$categories =$_product->getCategoryCollection();
foreach($categories as $_category) {
$cat_arr[] = $_category['entity_id'];
}
if($currentCategoryId==102){
// CATEGORY ID = 102 is IN-STOCK PRODUCT CATEGORY
$sizeStock=$_product->getAttributeText('size');
$day="Ready To Ship";
$searchfabric=$_product->getSearchfabric();
$searchcolor=$_product->getSearchcolor();
$make=$_product->getHandmake();
$handmake="HandMake";
$topname=$_product->getTopname();
<?php $i=$j+1;?>
<?php $j=$j+1;?>
<?php if($j<5){?>
<?php if ($i%$_columnCount==1): ?>
<ul class="products-grid">
<?php endif ?>
<?php if($j==1):?>
<li class="item first" style="height:434px; background:#FFF;">
<?php echo $this->getChildHtml("catalog"); ?>
</li>
<li class="item">
<?php echo $topname; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(162,324); ?>" width="162" height="324" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<div style="width:100%; border-bottom:none; height:80px;">
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if($make==1){ echo "<p>".$handmake."</p>";}else{}?>
<?php if($currentCategoryId==102){?>
<!-- display size -->
<p><?php echo $sizeStock; ?></p>
<?php } ?>
<p> <?php echo $day; ?></p>
</div>
</li>
so it came to my thought that it might be something in the store backend, somewhere around attribute modification.
Here is how the previous developer sorted and arranged the position of the size values I am not sure if this is the cause of problem.
Anybody is familiar with this problem?
Any answer is appreciated.
thank you in advance.
Did you try to reindex product data from "System"->"Index Management" ?
Please use this
$attribute_value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);
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 have a client who has accidentally added the products in the Related Products section rather than the Upsell Section. I have a file named upsell_slider.phtml that spits out the following:
<?php if(count($this->getItemCollection()->getItems())): ?>
<div class="box-collateral box-up-sell upsell-slider">
<h2><?php echo $this->__('Fashion Statement') ?></h2>
<?php $this->setColumnCount(4); // uncomment this line if you want to have another number of columns. also can be changed in layout ?>
<?php $this->resetItemsIterator(); ?>
<?php
$products_count = 0;
while($this->getIterableItem()){
$products_count++;
}
?>
<div <?php if ($products_count > 1): ?>id="block-upsell-slider"<?php else:?> class="no-slider" <?php endif; ?>>
<ul class="products-grid carousel-ul" id="upsell-product-table">
<?php $this->resetItemsIterator(); while ($_item=$this->getIterableItem()) : ?>
<li class="item grid_3 alpha">
<a class="product-image" href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(420, null); ?>" <?php echo MAGE::helper('ThemeOptions/Retina')->getRetinaData('upsell', $_item); ?> alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
<div class="product-details">
<h3 class="product-name"><?php echo $this->htmlEscape($_item->getName()) ?></h3>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php if ($products_count > 1): ?>
<div class = 'next'></div>
<div class = 'prev unselectable'></div>
<?php endif; ?>
</div>
<script type="text/javascript">
/* Upsell Block Slider */
if(jQuery('#block-upsell-slider').length) {
jQuery('#block-upsell-slider').iosSlider({
responsiveSlideWidth: true,
snapToChildren: true,
desktopClickDrag: true,
infiniteSlider: true,
/* navSlideSelector: '.sliderNavi .naviItem', */
navNextSelector: '.box-up-sell .next',
navPrevSelector: '.box-up-sell .prev'
});
}
function upsell_set_height(){
var upsell_height = 0;
jQuery('#block-upsell-slider li.item').each(function(){
if(jQuery(this).height() > upsell_height){
upsell_height = jQuery(this).height();
}
})
jQuery('#block-upsell-slider').css('min-height', upsell_height+2);
}
setTimeout(function(){
upsell_set_height();
}, 1000);
jQuery(window).resize(function(){upsell_set_height();});
/* Upsell Block Slider */
</script>
<?php endif ?>
And I can't for the life of me get it to look at the related products, rather than the upsell products.
I have a better solution. You can transform the related products in upsells with one query.
UPDATE `catalog_product_link` SET `link_type_id` = 4 WHERE `link_type_id` = 1;
Note. This will make move all the related products to upsells.
...and back up the table before trying it.
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.