Magento 1 article stock in shopping cart - Group articles - magento-1.9

How do I check the stock of e.g. group articles?
Everything I have tried so far:
<p class="availability">
<?php $gty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>
<?php
$thisProduct = Mage::getModel('catalog/product')->load($_item->getId());
if($thisProduct->isAvailable()):
echo $this->__('In stock');
else:
echo $this->__('Out of stock');
endif;
?>
<?php echo $this->__('Qty') ?>
getChildHtml('product_type_data_extra') ?> loadByProduct($_product)->getQty()?>
</p>
ends in the output 0 - that means no stock is displayed although the stock is displayed correctly on the article detail page and there is a stock available... only in the shopping cart this does not work.

Related

How to display out of stock status for both simple product & configurable product in Product page magento1.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 }
}

ACF - repeater only showing 1 row on blog page

I have a repeater in my footer.php file and it works for the entire website, but whenever I go to the blog page (index.php), the repeater only displays one row of the entire repeater and I don't know why this is happening.
I've tried putting get_option('page_for_posts') as the repeater field's second parameter, but this didn't work.
This is how it looks on every page except the blog page.
and this is how it looks on the blog page itself:
It only shows one row on the blog page, which is the About Us column.
Here's the code:
<?php if ( have_rows('post_object_repeater') ) : ?>
<?php while( have_rows('post_object_repeater') ) : the_row(); ?>
<?php $header = get_sub_field( 'header' ); ?>
<div class="<?php echo $number_of_columns; ?> col-md-6 col-12 list-column">
<?php
$posts = get_sub_field('post_object_relationship');
if( $posts ): ?>
<ul class="list-unstyled <?php if ( ! $header ): echo 'no-header'; endif; ?>">
<?php if ( $header ): ?>
<li class="header mb-3 font-weight-bold text-uppercase"><?php echo $header; ?></li>
<?php endif; ?>
<?php foreach( $posts as $post): ?>
<?php setup_postdata($post); ?>
<li class="list-item">
<?php the_title(); ?>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
This repeater does have a relationship field inside to pull each of the individual pages or custom post types of the website. Would anyone have an idea why not all of the repeater rows display on a blog page, but work on all other pages?
Have you tried
if(have_rows('post_object_repeater', 'option')
while(have_rows('post_object_repeater', 'option'))
etc.
????

How can I save the items of answers for a questions in an array so that I send them to the database using a controller and a model

The code below is the view page used to display the different kinds of questions and their choices.. Questions like Fill in the blanks and multiple answer consists of more than one answer element.
<?php echo form_open('courseware/saveanswer'); ?>
<?php if(count($test_questions)):?>
<?php $i = 1 ?>
<ol>
<?php foreach($test_questions as $test_question):?>
<li>
<?php if($test_question->question_type == 'Fill-blanks'):?>
<?php $test_question->question_text = str_replace('___',form_input(array('name'=>'answer[]','id'=>'answer_'.$i++,'type'=>'text','size'=>'8')),$test_question->question_text)?>
<?php endif ?>
<?php echo $test_question->question_text ?>
<?php if($test_question->question_type == 'Multi-choice'):?>
<?php $choices = explode("\n", $test_question->question_choices)?>
<?php if(count($choices)):?>
<ul>
<?php foreach($choices as $choice):?>
<li><?php echo form_radio('answer'.$test_question->question_id,$choice) ?> <?php echo $choice ?></li>
<?php endforeach ?>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php endif ?>
<?php elseif($test_question->question_type == 'Multi-answer'):?>
<?php $choices = explode("\n", $test_question->question_choices)?>
<?php if(count($choices)):?>
<ul>
<?php foreach($choices as $choice):?>
<li><?php echo form_checkbox('answer',$choice) ?> <?php echo $choice ?></li>
<?php endforeach ?>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php endif ?>
<?php elseif($test_question->question_type == 'True/False'):?>
<ul>
<li><?php echo form_radio('answer_'.$test_question->question_id,1) ?> True</li>
<li><?php echo form_radio('answer_'.$test_question->question_id,0) ?> False</li>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php else:?>
<?php endif ?>
</li>
<?php endforeach?>
<?php echo form_close(); ?>
below is a screenshot.
The question page looks like this ..
I want an array that has all the answers selected and sends the data to the database
The database consists of the table tbl_response and has the columns
test_reponse_id,
test_reponse_text ,
question_id ,
there's a number of ways to store multiple elements in a single value. You can use an implode() function to save as a string with a separator, as you are already doing with the $test_question->question_choices , which is separated by a '\n'. The cleanest alternative to that is often using json_encode().
either way, as you're presumably going to be comparing the selected answer(s) to something else, i suggest being careful about keeping the format and order consistent.

Display youtube iframe if url stored in mySQL

I created a form where we can register youtube embed url in a post.
I'd like to display the iframe only if an url has been register for this post.
I made this code to display the report information :
<?php
$req = $db->query('SELECT id, title, author, category, date_event, country, city, content, tag, youtube FROM report ORDER BY date_creation DESC LIMIT 0, 10');
while ($data = $req->fetch())
{
?>
<div class="news">
<h3><?php echo htmlspecialchars($data['title']); ?></h3>
<p>Author: <?php echo htmlspecialchars($data['author']); ?></p>
<p>Category : <?php echo htmlspecialchars($data['category']); ?></p>
<p>Date of the event : <?php echo htmlspecialchars($data['date_event']); ?></p>
<p>Country : <?php echo htmlspecialchars($data['country']); ?></p>
<p>City : <?php echo htmlspecialchars($data['city']); ?></p>
<p class="display_list"><?php echo html_entity_decode($data['content'], ENT_HTML5 , 'UTF-8'); ?></p>
<p>Tag : <?php echo htmlspecialchars($data['tag']); ?></p>
<p>Youtube : <?php echo htmlspecialchars($data['youtube']); ?></p>
<p>
<?php
$youtube=$data['youtube'];
if($youtube==1){
echo "<p>display iframe</p>";
}else{
{
echo "<p>don't display iframe</p>";
}
}
?>
</p>
The request to display url with works correctly. the urls are displayed if they are contained in the row.
However the condition code displays the same answers for all the posts : "don't display iframe".
The condition statement for $youtube variable is certainly not right but I can't figure out the issue.
you have assigned $youtube=1; instead of $youtube=$data['youtube']; in the code
try this
<?php
$req = $db->query('SELECT id, title, author, category, date_event, country, city, content, tag, youtube FROM report ORDER BY date_creation DESC LIMIT 0, 10');
while ($data = $req->fetch())
{
?>
<div class="news">
<h3><?php echo htmlspecialchars($data['title']); ?></h3>
<p>Author: <?php echo htmlspecialchars($data['author']); ?></p>
<p>Category : <?php echo htmlspecialchars($data['category']); ?></p>
<p>Date of the event : <?php echo htmlspecialchars($data['date_event']); ?></p>
<p>Country : <?php echo htmlspecialchars($data['country']); ?></p>
<p>City : <?php echo htmlspecialchars($data['city']); ?></p>
<p class="display_list"><?php echo html_entity_decode($data['content'], ENT_HTML5 , 'UTF-8'); ?></p>
<p>Tag : <?php echo htmlspecialchars($data['tag']); ?></p>
<p>
<?php
$youtube=$data['youtube'];
if($youtube==1){
echo "<p>display iframe</p>";
}else{
{
echo "<p>don't display iframe</p>";
}
}
?>
</p>

Way to show post views in while loop?

I have a loop showing post titles and excerpts:
<?php query_posts('category_name=blog&showposts=6'); while (have_posts()) : the_post(); ?>
<div class="panel">
<h2><?php the_title(); ?></h2>
<div class="excerpt"><?php the_excerpt(); ?></div>
<a class="readmore" href="<?php the_permalink(); ?>">Continue Reading</a>
</div>
<?php endwhile; wp_reset_query(); ?>
I want to be able to show how many views each post has had in this loop as well.
I am aware there are many ways to show this on the post page (single.php), but I cant find any to show it in a loop. Plugins only seem to work on the single.php page as well.
Does anyone know a way to achieve this?
You will need to find out where the view count are getting stored for each post by the plugin. Generally it gets stored in post meta.
If this is the case, Then you need to use the following code to display the view count.
<?php query_posts('category_name=blog&showposts=6'); while (have_posts()) : the_post(); ?>
<div class="panel">
<h2><?php the_title(); ?></h2>
Views for this post: <?php echo get_post_meta(get_the_ID(),'meta_name_view_count',true); ?>
<div class="excerpt"><?php the_excerpt(); ?></div>
<a class="readmore" href="<?php the_permalink(); ?>">Continue Reading</a>
</div>
<?php endwhile; wp_reset_query(); ?>
meta_name_view_count this will be the name what plugin uses to store the view count in wp_postmeta table