Magento 1.7.0.2 Checkout shipping - magento

I have a small problem with jquery that I want to use in my magento one page checkout.
I currently use flat rate for international delivery that is set to 0 because I have a variable costs of shipping.
For this reason I have a jquery email enquiry that sends all contents of the shopping cart in e-mail.
Now what I want to do is: when the customer arrives and selects flat rate delivery option I want to disable the Continue button and enable Email Enquiry button, but that does not work in my checkout. It does in jsfiddle. I think this is due to the fact that shipping methods are in available.phtml and buttons are in different file - shipping_methods.phtml. Any help will be appreciated
Here's my code:
<script type="text/javascript">
//<![CDATA[
var shippingMethod = new ShippingMethod('co-shipping-method-form', "<?php echo $this- >getUrl('checkout/onepage/saveShippingMethod') ?>");
//]]>
</script>
<div id="onepage-checkout-shipping-method-additional-load">
<?php echo $this->getChildHtml('additional') ?>
</div>
<div class="buttons-set" id="shipping-method-buttons-container">
<p class="back-link"><small>« </small><?php echo $this->__('Back') ?></p>
<button id="the_other_button" type="button" title="Email Enquiry" class="button" onclick="javascript:readEmailInfo();"><span><span style="padding: 0 13px;">Email Enquiry</span></span></button>
<button id="the_button" type="button" class="button" onclick="shippingMethod.save()"><span><span><?php echo $this->__('Continue') ?></span></span></button>
<span id="shipping-method-please-wait" class="please-wait" style="display:none;">
<img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo
$this->__('Loading next step...') ?>" title="<?php echo $this->__('Loading next step...') ?>"
class="v-middle" /> <?php echo $this->__('Loading next step...') ?>
</span>
</div>
</form>
<script>
if ($("#s_method_flatrate_flatrate:checked")){
$('#the_button').hide();
$('#the_other_button').show();
}
</script>

Try this:
<script>
jQuery.noConflict();
if (jQuery("#s_method_flatrate_flatrate").is(":checked")){
jQuery('#the_button').hide();
jQuery('#the_other_button').show();
}
</script>
$ is also used by Magento's default prototype.js, which will conflict with jQuery's $.

You can do that by this:
<script>
$j = jQuery.noConflict();
if ($j("#s_method_flatrate_flatrate").is(":checked"))
{
$j('#the_button').hide();
$j('#the_other_button').show();
}
</script>
By using this you can resolve jQuery Conflict.

Related

Search results not showing in dashboard

When my customers search in my searchbox (which uses form.mini.phtml), there results won't show up in my dashboard (Magento 1.7).
Here is my code:
<?php
$catalogSearchHelper = $this->helper('catalogsearch');
?>
<div class="search-form">
<form id="search_mini_form" action="<?php echo $this->getUrl('search/result') ?>" method="get">
<input id="search" type="text" name="query" value="" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" />
<button><?php echo $this->__('Search') ?></button>
</form>
<script type="text/javascript">
var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('Search Products and Pages...') ?>');
</script>
</div>
<i><?php echo $this->__('Advanced Search'); ?></i>
The results won't show up in my Dashboard, and in the search terms menu under 'Catalog'.
Where should this save action take place?
If i manually add a search term under Catalog -> Search terms, it does show up at 'Latest 5 search terms'.
Check if the setting for popular search terms is enabled under
/admin/system_config/edit/section/catalog -> Search Engine Optimizations
and flush your cache.

How to create an unsubscribe page in magento

I would like to create a direct unsubscribe page in magento, I found this instruction to follow but the steps 1 and 2 are not clear As I'm not a professional.
Can someone please help me clarify these two steps. Where to create the "unsubscribe.phtml" page? How to add the just created block in it?
Thank you in advance.
1. Create a phtml page say “unsubscribe.phtml” containing the code to create the unsubscribe form.
<?php $newsletterObj = new Mage_Newsletter_Block_Subscribe(); ?>
<div class="newsletter-unsubscribe">
<div class="newsletter-unsubscribe-title"><?php echo $this->__('Submit your email id to unsubscribe newsletter') ?></div>
<form action="<?php echo $newsletterObj->getUnsubscribeFormActionUrl() ?>” method="post" id="newsletter-validate-detail">
<div class="block-content">
<div class="input-box">
<input type="text" name="email" id="newsletter" title="<?php echo $this->__('Sign up for our newsletter') ?>” class="input-text required-entry validate-email” value="<?php echo $this->__('Enter Your Email Here') ?>” onfocus="if(this.value==’<?php echo $this->__('Enter Your Email Here') ?>’)this.value=’’;” onblur="if(this.value==’’)this.value=’<?php echo $this->__('Enter Your Email Here') ?>’;”
/>
</div>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Submit') ?>” class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
</div>
</div>
</form>
<script type="text/javascript\">
//<![CDATA[
var newsletterSubscriberFormDetail = new VarienForm(’newsletter-validate-detail’);
//]]>
</script>
</div>
2) Create a CMS page. Add the just created block in it. So that your CMS page will contain that form.
3) Now in page \app\design\frontend\base\default\template\newsletter\subscribe.phtml add the code to add a link of the cms page.
<div class="unsubscribe">
<?php echo $this->__('Unsubscribe') ?>
</div>
4) In page \app\code\core\Mage\Newsletter\Block\Subscribe.php add a function to create the form action url which is called in the “unsubscribe.phtml”.
public function getUnsubscribeFormActionUrl()
{
return $this->getUrl(’newsletter/subscriber/unsubscribecus’, array(’_secure’ => true));
}
5) Now in \app\code\core\Mage\Newsletter\controllers\SubscriberController.php page add new action for unsubscribe process.
/**
* Unsubscribe newsletter from frontend
*/
public function unsubscribecusAction()
{
$email = $this->getRequest()->getParam(’email’);
$subsModel = Mage::getModel(’newsletter/subscriber’);
$subscriber = $subsModel->loadByEmail($email);
$id = (int) $subsModel->getId();
$code = (string) $subsModel->getCode();
if ($id && $code) {
$session = Mage::getSingleton(’core/session’);
try {
Mage::getModel(’newsletter/subscriber’)->load($id)
->setCheckCode($code)
->unsubscribe();
$session->addSuccess($this->__(’You have been unsubscribed.’));
}
catch (Mage_Core_Exception $e) {
$session->addException($e, $e->getMessage());
}
catch (Exception $e) {
$session->addException($e, $this->__(’There was a problem with the un-subscription.’));
}
}
$this->_redirectReferer();
}
Since a can't leave a comment and this question isn't marked as solved yet, i'll assume you still need an answer.
I would suggest placing the unsubscribe.phtml file in /template/newsletter/
For step 2 you can use this code
{{block type="core/template" template="newsletter/unsubscribe.phtml"}}
so the page will contain your form.
If you already figured out how to do this, please post an answer to your own question further on.
Would it be an idea to add an unsubscribe button next to the subscribe button (or allow for a variable in the block call that sets it to yes/no display) - this way you capture both

Magento | Use quantity increments and ajax add to cart on category page and product view

Here is the scenario:
I'm using an ajax add to cart extention to add product to cart without refreshing page.
And I have modified the list.phtml file to have some quantity increment function which adds a "+" and "-" plus and minus buttons inputs. (source: http://jigowatt.co.uk/blog/magento-quantity-increments-jquery-edition/).
The problem explained with 2 different observations:
1st/ If I increase the quantity by clicking on the + button input, quantity changes correctly as I see the value changing in the input box , but then I click on add to cart button, and there's only 1 product added. No matter how many times I clicked on the + button to get the quantity I wanted, the number added to cart is always 1.
2nd/ If I type the desired quantity number in the quantity box manually, 5 for example, no problem : cart is refreshed with 5 items.
So basically only when clicking on the increment button + , the number of items aren't added, only one gets added.
Here is the code which adds the increment function and adds the + and - buttons:
jQuery("div.quantity").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');
jQuery(".plus").click(function()
{
var currentVal = parseInt(jQuery(this).prev(".qty").val());
if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 0;
jQuery(this).prev(".qty").val(currentVal + 1);
});
jQuery(".minus").click(function()
{
var currentVal = parseInt(jQuery(this).next(".qty").val());
if (currentVal == "NaN") currentVal = 0;
if (currentVal > 0)
{
jQuery(this).next(".qty").val(currentVal - 1);
}
});
Now, to have the ajax add to cart button work with the quantity input box on list.phtml, some modification had to be made (source: http://forum.aheadworks.com/viewtopic.php?f=33&t=601)
The original code which must be replaced is :
<!-- Find this block of code: -->
<?php if($_product->isSaleable()): ?>
<button type="button" class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
It must be replaced with this code below, as explained on the forum link posted above:
<!-- And replace it with this block of code: -->
<?php if($_product->isSaleable()): ?>
<script type="text/javascript">
function setQty(id, url) {
var qty = document.getElementById('qty_' + id).value;
document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="button" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Add to Cart</span></span></button>';
}
</script>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_product->getId(); ?>"><button type="button" class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
<?php else: ?>
I don't know why the quantity added to cart is only correct when typing the value manually. I would need the correct quantity added to cart also when using the + (plus) or - (minus) buttons . For some reason the quantity changes in the input box, but this value is not the one in the cart after the add to cart is clicked (always 1 product added to cart).
What is causing this problem ? And what would be the solution to resolve this ? I would love to understand and fix this as I've been trying this whole afternoon. Many thanks.
Was going to put this in as a comment, but need to format it for easier viewing
I would recommend opening the page in Google Chrome and then using the developer tools to do a couple of things:
Step through the jQuery code using the Script panel - you can then make sure that the code is setting the quantity correctly.
Check that the request going via Ajax is correct. You can do this by looking at the Network panel, identifying the Ajax call and checking that the qty value going to the controller is correct.
Personally, I'd be checking that the setQty function is being fired by the + (plus) & - (minus) buttons, or at least that the setQty function is doing the same thing as the plus & minus buttons are.
From the code you have posted it looks like this line in the setQty function may be required in the plus & minus button code
document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="button" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Add to Cart</span></span></button>';
Cut the setQty function from input tag.
paste it instead of setLocation function in Add To Cart Button tag
Use onmousedown event Add To Cart Button tag.
Use onmouseup event within script
Totally the code looks like
<?php if($_product->isSaleable()): ?>
<script type="text/javascript">
function setQty(id, url) {
var qty = document.getElementById('qty_' + id).value;
document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="button" onmouseup="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Add to Cart</span></span></button>';
}
</script>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<a class="decrement_qty" href="javascript:void(0)"> &nbsp - &nbsp</a>
<input type="text"
name="qty_<?php echo $_product->getId(); ?>"
id="qty_<?php echo $_product->getId(); ?>"
maxlength="12" value="1"
title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<a class="increment_qty" href="javascript:void(0)"> &nbsp + &nbsp</a>
<span id="cart_button_<?php echo $_product->getId(); ?>">
<button type="button"
class="button"
onmousedown="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');">
<span><span><?php echo $this->__('Add to Cart') ?></span></span>
</button>
</span>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
Use the following script to increment and decrement the value when click on anchor tags
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('.increment_qty').click(function() {
var oldVal = jQuery(this).parent().find("input").val();
if ( parseFloat(oldVal) >= 1 ) {
var newVal = parseFloat(oldVal) + 1;
jQuery(this).parent().find("input").val(newVal);
}
});
jQuery('.decrement_qty').click(function() {
var oldVal = jQuery(this).parent().find("input").val();
if ( parseFloat(oldVal) >= 2 ) {
var newVal = parseFloat(oldVal) - 1;
jQuery(this).parent().find("input").val(newVal);
}
});
});
</script>

How to call the image in the product view magento?

I want to call the image that loads into the larger view area of the magento product page.
In the product view page, I have more view images when clicked, it shows the image in the larger view, not in default pop up window. I want to call the full size image of whatever the image is loaded in the larger view area. Can someone tell me how do I do it?
I did some search and found
echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(163, 100);
But this gets only the image which was there by default. I want to be able to call any image that comes in the larger view area.
try this code
$this->helper('catalog/image')->init($_product, 'image')
this will get you the image on product view page.
ok I think this might save ur trouble. ITs Damn easy
Lets say ur main image area is <img id="main-image" src="main-image.jpg" />
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<a class="grouped_elements" href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(260,null) ?>"
title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" rel="group1">
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(70,null) ?>"
width="70" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
</a>
</li>
<script type="text/javascript">
//<![CDATA[
jQuery("a.grouped_elements").click(function(){
$('#main-image').attr('src', this.attr('href'));
});
//]]>
</script>
Hope this should help ...
I think u must check the file
app\design\frontend\base\default\template\catalog\product\view
& its declared as in the
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
this file gives u the Main Image & also the Gallery Images. of course u'll get only enabled images.
so What I understand from the subsequent comments. u need these images in a fancybox. there has to be a slideshow thing previou next etc. right??
ok Here it is what u can do. Create a new file under
app\design\frontend\base\default\template\catalog\product\view\fancy.media.phtml
(or u can use ur theme folder instead of base/default)
in ur catalog.xml add this block under
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
<block type="catalog/product_view_media" name="fancy.media" template="catalog/product/view/fancy.media.phtml"/>
now in media.phtml u'll get all the images & there URLs. code the fancybox & pass the image url to it. &
& yeah don't forget to call this block in ur product page i.e.
app\design\frontend\base\default\template\catalog\product\view.phtml
by echo $this->getChilHtml('fancy.media')
I hope this must solve problem
UPDATE:
try this in fancy.media.phtml:
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<a class="grouped_elements" href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(260,null) ?>"
title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" rel="group1">
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(70,null) ?>"
width="70" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
</a>
</li>
<?php endforeach; ?>
<script type="text/javascript">
//<![CDATA[
$("a.grouped_elements").fancybox();
//]]>
</script>
Please refer to the Docs of fancybox, fancybox how to
I think ur requirement is if somebody clicks on the More-views on product page it must get open in fancybox. Right?? so u can place this code in media.phtml also. no need to create a new file & no need to edit the catalog.xml.
If u make this working then feel free to accept my answer.
I got the desired result by adding a button on media.phtml
<a class="fullscreen" href="#image" onclick="document.getElementById('image').style.width='100%'; return false; " > <img src="<?php echo $this->getSkinUrl('images/zoom_full.jpg') ?>" alt="<?php echo $this->__('Full Screen') ?>" title="<?php echo $this->__('Full Screen') ?>" /></a>
<script type="text/javascript"> j(document).ready(function() {
j(".fullscreen").fancybox({ 'transitionIn': 'fade', 'transitionOut':
'none', 'overlayColor': '#fff', 'overlayOpacity':1,
'hideOnOverlayClick':false }); </script>

Wordpress ajax loop refresh on click

I display a random post loop on a page. I'd like to put a "refresh" link to refresh the content of the loop via ajax.
Is this possible?
This is my loop:
<ul id="content-inner" class="thumb-grid clearfix">
<?php query_posts('posts_per_page=20&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<img src="<?php echo $my_image_url = get('thumbnail'); ?>" alt="" />
<span class="title"><?php the_title(); ?></span>
<span class="feat"><?php $articletags = strip_tags(get_the_tag_list('',', ',''));echo $articletags;?></span>
</a>
</li>
<?php endwhile;?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</ul>
Thanks
Put the random post code in a div (if you haven't already), and refresh the contents of that div with JQuery...
Something like this should work (but I haven't had time to test)...
In the Head of your page reference JQuery, then use JQuery.Ready to load the first random post (for initial page load):
<head>
<script> /*...reference JQuery...*/ </script>
<script>
jQuery(document).ready(function($) {
$("#randomdiv").html("<?php getRandomPost() ?>");
});
</script>
</head>
<body>
....
<div id="randomdiv">[placeholder text]</div>
<a id="refresh" href="#">click</a>
<!-- Then for the REFRESH:
make sure this script occurs AFTER your div (above) -->
<script>
$(function() {
$("#refresh").click(function(evt) {
$("#randomdiv").html("<?php getRandomPost() ?>");
evt.preventDefault();
})
})
</script>
</body>
So put your entire loop code in a function called getRandomPost() (or something) and place it in your wordpress "functions.php" file..., then just call "$("#randomdiv").html("");" in the head of your page for initial load, then in the body as I've shown for the refresh...

Resources