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

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>

Related

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.

How to show the message “No Products” when there's no products in my custom block?

I need to show the message "No Products" or "There are no products matching the selection" when there's nothing to show in my block.
<?php
$manufacturer = Mage::registry('current_product')->getMerchantName();
$productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('merchant_name',$manufacturer);
$productCollection->getSelect()->order('RAND()');
$productCollection->getSelect()->limit(5);
foreach ($productCollection as $_product)
?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(228) ?>" width="228" height="228" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<div class="product-details">
<p class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></p>
<?php
$merchant_name = $_product->getAttributeText('merchant_name');
if ($merchant_name){?>
<div>by <?php echo $merchant_name;?> </div>
<?php }
else if ($_product->getIsEbayaffiliate()) { ?>
<div>by eBay</div>
<?php }
else { ?>
<div>by Home Done</div>
<?php } ?>
Also I need to add getPriceHtml to the above code to show the product price.
I have tried <?php echo $this->getPriceHtml($_item, true) ?>
There you go:
(Advice: use closed tags like <?php if(): ?> for better readability)
<?php if(is_array($productCollection) && count($productCollection) ): ?>
<?php foreach ($productCollection as $_product): ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(228) ?>" width="228" height="228" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<div class="product-details">
<p class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></p>
<?php $merchant_name = $_product->getAttributeText('merchant_name'); ?>
<?php if ($merchant_name):?>
<div>by <?php echo $merchant_name;?> </div>
<?php elseif($_product->getIsEbayaffiliate()): ?>
<div>by eBay</div>
<?php else: ?>
<div>by Home Done</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php else: ?>
// here goes whatever you want to display if no products found in list
<?php endif; ?>

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; ?>

display blog posts on static page

I am rather new to Wordpress and have a question. I have created my own theme, which all seems to work fine. But, I am having one issue. I want to create my blog page (with all the posts) on a page other than my home page. So, in my theme folder, I created a page template called blog.php:
<?php
/*
Template Name: blog
*/
?>
<?php get_header(); ?>
<table id="about-table" >
<tr>
<td colspan="7">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_time("jS F"); ?>
<?php comments_number("0","1","%"); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</td>
</tr>
</table>
<?php get_footer(); ?>
Then, I created a page in wordpress called "blog" as well, in the "pages" section in the dashboard. I then assigned its template to the above "blog" template. The problem is, though, that the code does not work as it should. Instead of showing me the titles, comments, etc of the posts, it displays some other info. On the other hand, if i just copy this:
<table id="about-table" >
<tr>
<td colspan="7">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_time("jS F"); ?>
<?php comments_number("0","1","%"); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</td>
</tr>
</table>
to my index page, it works fine. So, how do I display all my post info on a page other than the home page?
I wanted to provide you with a simpler loop as a second option. If you use this and set Reading settings to the specific blog page this works well:
<?
/*
Template Name: Blog Template Example
*/
?>
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link(); ?></div>
<div class="prev-posts"><?php previous_posts_link(); ?></div>
</div>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
How about you do something like this:
blog-template.php:
<?php/*
Template Name: Blog Page
*/
?>
<?php get_header(); ?>
<?php get_template_part( 'layout-page', 'blog' );?>
<?php get_footer(); ?>
layout-page-blog.php:
<?php
the_post();
$title = get_the_title();
$baselink = get_permalink();
$category = get_field('category_blog');
if( !empty($category) ){
$post_per_page = get_option('posts_per_page');
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$categoryID = get_category_id($category);
$total = get_post_count(array($categoryID));
$the_query = new WP_Query("posts_per_page={$post_per_page}&cat= {$categoryID}&paged={$paged}");
?>
<div id="wrapper">
<div id="content">
<h1 class="title"><?php echo $title; ?></h1>
<div class="content-middle">
<div class="node">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<div class="content">
<?php echo content(150); ?>
</div>
<div class="read-more">Read more</div>
<?php endwhile; ?>
<br/><br/>
<div class="wp-paginate">
<?php
wp_reset_query();
echo paginate_links( array(
'base' => $baselink.'%_%',
'total' => ceil($total/$post_per_page),
'current' => $paged,
));
?>
</div>
</div>
</div>
</div> <!-- end content -->
<div style="clear:both"></div>
</div>
<?php
}
?>
This could all be in one file, or you can use it in two pieces as I have written it.
EDIT:
Sorry I have it set to also grab the images from the post. I think this is the functions code you need:
function get_images_by_cat($id){
$limit = 1000;
$the_query = new WP_Query("posts_per_page={$limit}&cat={$id}");
$arr = array();
while ( $the_query->have_posts() ) {
$the_query->the_post();
$title = get_the_title();
$image_src = get_field('banner_image');
$image_link = get_field('banner_link');
$arr[] = array(
"title" => $title,
"link" => $image_link,
"image" => $image_src,
);
}
wp_reset_query();
return $arr;
}

Wordpress category, get all its posts

I am currently finish of my theme for a wordpress website that I am building, I am having a problem getting my categories to work though.
I am lost as to how I can loop through the current category if I am at a URL of say "/category/category-name" how would I loop the posts that belong to the category "category name".
I I do the following on my template
<p>Category: <?php single_cat_title(); ?></p> I get the following output
Category Name
So how do I loop through that categories posts?
Category.php
<?php get_header(); ?>
<article class="content">
<section class="top">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</section>
<section class="middle">
</section>
</article>
<?php get_footer(); ?>
page-news.php
<?php get_header(); ?>
<article id="content">
<section class="top">
<?php query_posts('post_type=news'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="news">
<?php the_post_thumbnail(); ?>
<h2><?php echo strtolower(the_title()); ?></h2>
<span class="posted"><?php the_date("l jS M Y"); ?></span>
<?php
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
?>
<p><?php echo substr(strip_tags($content), 0, 400).'…' ; ?>Read More</p>
<p class="tags">
<strong>Categories:</strong>
<?php
$post_categories = wp_get_post_categories( $post->ID );
$cats = array();
foreach($post_categories as $c){
$cat = get_category( $c );
$cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
}
?>
<?php foreach($cats as $k => $v) : ?>
<?php echo $cats[$k]['name']; ?>
<?php endforeach; ?>
</p>
<p class="tags">
<strong>Tags: </strong>
<?php $tags = wp_get_post_tags($post->ID); ?>
<?php foreach ($tags as $tag) : ?>
<?php echo $tag->name; ?>
<?php endforeach; ?>
</p>
</section>
<?php endwhile; endif; ?>
<?php get_sidebar('news'); ?>
</section>
<section class="middle">
</section>
</article>
So page-news.php are where my news article reside, and the user can get the category using the link generated by <?php echo $cats[$k]['name']; ?>
I don't think you're outputting anything in category.php based on the code above. the_post() doesn't echo anything. It just puts the next record into $post. Try this...
<?php
get_header();
$cat = get_category(get_query_var("cat"));
var_dump($cat); //make sure that there really is a valid category and it's the right one
?>
<h1 class="page-title"><?php echo $cat->name?></h1>
<?php
if (have_posts()) {
while (have_posts()){
the_post();
<h2><?php the_title()?></h2>
<?php the_content()?>
<?php
}
} else {
?>
<p>No posts found!</p>
<?php
}
?>
<?php
get_footer();
?>
In page-news.php you should probably consider using the_category() to echo out the category links rather than constructing the links yourself -- that way you'll know that the links are valid....
<p class="tags"><?php the_category()?></p>
You can use this function inside your page template to loop the posts