How to display out of stock status for both simple product & configurable product in Product page magento1.9 - magento-1.9

I have magento website that develop using 1.9 version and i need to display the out of stock status on product page for both simple product & configurable product
I have tried below method and It's only getting status of simple products
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
$qty = $stock->getQty();
What i need is How to display the out of stock status for simple and configurable products in product page

This code works for me,
Hope this will help you.
if( $_product->getTypeId() == 'simple' ){
if ($_product->getStockItem()->getIsInStock()<= 0) { ?>
<span class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></span>
<?php }else { ?>
<span class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></span>
<?php };
}
else{
$_product->getTypeInstance(true)->getUsedProducts ( null, $_product);
foreach ($_product->getTypeInstance(true)->getUsedProducts ( null, $_product) as $simple) {
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();
$stockTotal = $stockTotal + $stock;
}
if ($stockTotal <= 0){ ?>
<span class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></span>
<?php } else{ ?>
<span class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></span>
<?php }
}

Related

count up the rows in acf (repeater-field) and add html output for every row

I want to output a list element () for each row of an ACF repeater field. As soon as a new row is created, a new list element shoul be created with the value of the counter (cout up).
here is the code. the list elements should cout up according to the number of rows:
HTML:
<ul>
<li data-id="1" class="active">1</li>
<li data-id="2">2</li>
<li data-id="3">3</li>
<li data-id="4">4</li>
<li data-id="5">5</li>
<li data-id="6">6</li>
<li data-id="7">7</li>
<li data-id="...">...</li>
</ul>
PHP (ACF):
<?php
$i = 1;
if (have_rows('referenz-slide')) :
$counter = 0;
while (have_rows('referenz-slide')) : the_row();
$counter++;
// vars
$title = get_sub_field('title');
$link = get_sub_field('link');
$text = get_sub_field('text');
?>
<?php $state = "";
if ($i == 1) {
$state = "active";
} else {
$state = "hidden";
} ?>
<div class="referenz-content <?php echo $state; ?>" id="ref-<?php echo $i; ?>" data-referenz="<?php echo $i; ?>">
<h4 class="referenz-headline"><?php echo $title; ?></h4>
<p><?php echo $text; ?></p>
Jetzt mehr erfahren
</div>
<?php $i++;
endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
I would like to increment the list items and the value of the data id (html output) according to the number of ACF rows. Can someone help?
So you pretty much have it all there already
<ul>
<?php while (have_rows('referenz-slide')) : the_row();?>
<li data-id="<?php echo $i;?>" class="<?php echo $state; ?>">
<?php echo $i;?>
</li>
<?php $i++; ?>
<?php endwhile; ?>
</ul>

Magento is not updating Shipping cost on changing the Shipping method radio button

I change the shipping method as you can see in the screenshot but magento does not refresh the inner page with the calculated total shipping cost.I think this is a bug in version 1.9. Here you can see the screenshot .Magento ver. 1.9.2.4
When I change the radio button from one shipping method the onestepcheckout does not refresh the inner page with calculated cost.
How can I refresh the inner page with javascript.
Thanks
Add the below code in available.phtml file
<?php if (!($_shippingRateGroups)): ?>
<strong><?php echo Mage::helper('oscheckout')->__('Sorry, no quotes are available for this order at this time.') ?></strong>
<?php else: ?>
<dl class="shipment-methods">
<?php $methodcount = count($_shippingRateGroups); $check_default = 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
<dd><?php echo $this->getCarrierName($code) ?></dd>
<?php foreach ($_rates as $_rate): ?>
<dt style="margin-bottom: 5px;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<input <?php echo $check_default == 1 ? 'checked="checked"':'' ?> name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" />
<label for="s_method_<?php echo $_rate->getCode() ?>"> <?php echo $_rate->getMethodTitle() ?>
<strong>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo Mage::helper('oscheckout')->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; $check_default++; ?>
<?php endforeach; ?>
</dl>
<?php endif;
?>
Add this script in the same file
<script type="text/javascript">
<?php if($methodcount >= 1): ?>
document.observe('dom:loaded', function(){
shipping.loadReview();
var payment_methods = $('ajax-payment-methods');
//payment_methods.update('<div class="ajax-load"> </div>');
payment.reloadPaymentBlock();
// reloadPaymethod();
});
<?php endif; ?>
$$('dl.shipment-methods input').invoke('observe', 'click', function() {
shipping.loadReview();
var payment_methods = $('ajax-payment-methods');
//payment_methods.update('<div class="ajax-load"> </div>');
payment.reloadPaymentBlock();
// reloadPaymethod();
});
</script>

current post custom taxonomy link in WordPress

I am trying to get current post custom taxonomy link and name separately to put some schema data and my code is:
<?php $args = array('taxonomy' => 'developer'); ?>
<?php $tax_menu_items = get_categories( $args );
foreach ( $tax_menu_items as $tax_menu_item ):?>
<meta itemprop="url" content="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"></meta>
<a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>">
<span itemprop="name"><?php echo $tax_menu_item->name; ?></span></a>
<?php endforeach; ?>
</div>`
The problem is that the above code is displaying all the "developer" which have at least one post and not the current post taxonomy.
How can I fix this!
<meta itemprop="url" content="<?php $terms = wp_get_post_terms( $post->ID, 'developer'); foreach($terms as $term) {
echo "" . get_term_link($term) . ""; } ?>"></meta>
<?php $terms = wp_get_post_terms( $post->ID, 'developer'); foreach($terms as $term) {
echo '<span itemprop="name">' . $term->name . '</span>'; }
?>

how can i change this mysql code to pdo?

i have this code in iclude for connect to database
i have in this file mysql connection function too but i decide change mysql to pdo
-include.php:
try{
$conn = new PDO('mysql:host=localhost;dbname=databasename', 'username', 'password');
return $conn;
}
catch(PDOException $e)
{
echo 'can not connect to database';
exit();
}
i have mysql query in index.php but i want change this code to pdo
<?php
$sql=mysql_query("SELECT id,col1 FROM tblname ORDER BY col4 DESC, col3 DESC, tzade DESC LIMIT 18");
if(mysql_num_rows($sql)) {
$j=0;
while($result = mysql_fetch_object($sql)) {
$j++;
if($result->id == $site_id){
?>
<a class="normal_link" href="l.php?lid=<?php echo $result->id; ?>&title=<?php echo title($result->col1);?>">
<div id="jadv">
<div><?php echo $j; ?></div>
<div><?php echo $result->col1; ?></div>
</div>
</a>
<?php
}
else{
?>
<a class="normal_link" href="l.php?lid=<?php echo $result->id; ?>&title=<?php echo title($result->col1);?>">
<div id="jadva">
<div id="jad"><?php echo $j; ?></div>
<div id="jad"><?php echo $result->col1; ?></div>
</div>
</a>
<?php
}
}
}
?>
how can i change mysql query in this code to pdo?
Read some tutorial (there are plenty even here on SO)
Run some simple queries to make yourself familiar with PDO
Start with rewriting.
You should read some doc about PDO and do some tutorial. But to help you, here is a really simple sample to begin with PDO :
<?php
$connexion = new PDO("mysql:host=$PARAM_hote;dbname=$PARAM_db_name", $PARAM_user, $PARAM_pwd); // DB connexion
$results=$connection->query("SELECT member FROM member ORDER BY member ASC"); // retrieving all entries from member table
$results->setFetchMode(PDO::FETCH_OBJ); // retrieving results as objects
while( $lines= $results->fetch() ) // retrieving list of member
{
echo 'user: '.$lines->member.'<br />'; // displaying members
}
$results->closeCursor(); // close results cursor
?>
And here a more sophisticated one with params (prepared query) :
<?php
// connection opening ...
$prepared_query=$connecion->prepare("SELECT id FROM member WHERE member_id= :id"); // query prepare
$prepared_query->execute(array( 'id' => 1 ));
$lines=$prepared_query->fetch(PDO::FETCH_OBJ);
echo $lines->id.'<br />';
?>
It's an old sample of mine I hope will help you.
Something like this:
<?php
$sql = "SELECT id,col1 FROM tblname ORDER BY col4 DESC, col3 DESC, tzade DESC LIMIT 18 ";
$sth = $conn->query($sql);
$sth->setFetchMode(PDO::FETCH_ASSOC);
if ($count = $sth->rowCount() > 0){
$j=0;
while ($row = $sth->fetch()) {
$j++;
if($row['id'] == $site_id){
?>
<a class="normal_link" href="l.php?lid=<?php echo $row['id'] ?>&title=<?php echo title($row['col1']);?>">
<div id="jadv">
<div><?php echo $j; ?></div>
<div><?php echo $row['col1'] ?></div>
</div>
</a>
<?php
}
else{
?>
<a class="normal_link" href="l.php?lid=<?php echo $row['id'] ?>&title=<?php echo title($row['col1']);?>">
<div id="jadva">
<div id="jad"><?php echo $j; ?></div>
<div id="jad"><?php echo $row['col1'] ?></div>
</div>
</a>
<?php
}
}
}
?>

Nested IF statements in PHTML

Evening,
I tried to edit a simple code in Magento, yet im totaly new to PHTML and im having problems with basics...
I wanted to check the title to set a custom div for the translator to invoke...
This part of the edited PHTML code does not work...
<?php if( $this->getConfig('title') ): ?>
<?php if( $this->getConfig('title') == 'Categories' ?>
<div class="block-title"><strong><?php echo $this->__('Categories') ?></strong></div>
<?php else: ?>
<div class="block-title"><strong><?php echo $this->getConfig('title') ?></strong></div>
<?php endif ?>
<?php endif; ?>
While this original code works:
<?php if( $this->getConfig('title') ): ?>
<div class="block-title"><strong><?php echo $this->getConfig('title') ?></strong></div>
<?php endif; ?>
Can some expert please pinpoint an error so I wont spend whole bunch of time on this?
Thanks in advance.
<?php if( $this->getConfig('title') ): ?>
<?php if( $this->getConfig('title') == 'Categories'): ?>
---^
<div class="block-title"><strong><?php echo $this->__('Categories') ?></strong></div>
<?php else: ?>
<div class="block-title"><strong><?php echo $this->getConfig('title') ?></strong></div>
<?php endif; ?>
---^
<?php endif; ?>