My Recent Orders on home page, outside of user dashboard - magento

I need to know if I need to create a widget for something like this, or just add a recent orders block to the home page layout.xml.
it should only reflect order for that store.
I know that the user has to be logged in for this to work, but there could be some cookie magic applied to detect the user, and display a short list of recent orders, without displaying the items, which I think is not a massive privacy / security issue.
This is for use in a mobile app, where space is limited, and quick links are helpful...
There will then simply be a link to reorder / view as in the dashboard, and that view would require a descent login.
What is the best way to go about it, if at all possible.
this is a Paypal app, and the recent orders are seen via:
http://www.sitename.com/storename/jsonsales/order/recenttemplate?s=2752732063744
Thanks in Advance.

On top of my head, what I would do is create a custom module with observer to catch when order placed, trigger the process of storing the order in the cookie (e.g. last 3 orders?)
Then just create a block in that module to read the data from the cookie.
After that render that block into the template (either via editing appropriate .phtml or create your own .phtml and add it inside layout.xml).
Hope this helps.

For those that might want to try this, with a module called Paypal order Ahead.
Because this is a paypal specific web app, I was able to do this using the javascript functions calling the json templates.
On the /app/design/frontend/paypal/test/template/cms/index.phtml I added the following:
<div class="content-box greybg recentordercontainer">
<div id="productError_<?php echo $sid; ?>" style="display:none"></div>
<div class="page-title text-title"><?php echo $this->__('My Recent Orders'); ?></div>
<div id="recentorder-list-box_<?php echo $sid; ?>" class=""></div>
<div class="cart-empty" id="cart-empty_<?php echo $sid; ?>" style="display:none">
<div class="box-shadow">
<div class="error-desc cart-row2" style="margin-top:10px;"><?php echo $this->__('You have not yet made any purchases.'); ?></div>
</div>
<div class="pay-now" id="contshop_<?php echo $sid; ?>">
<?php echo Mage::getStoreConfig('checkout/options/continue_shopping_text'); ?>
</div>
</div>
</div>
Then I added some javascript in the script section at the bottom of this template:
getRecentOrderBlockJSON("<?php echo $sid; ?>")
function getRecentOrderBlockJSON(id) {
$.getJSON(storeRootUrl+"/jsonsales/order/recent", function(jsonObj) {
renderRecentOrderBlock(jsonObj,id);
});
}
function renderRecentOrderBlock(jsonObj,id) {
var dataObj = jsonObj.recentorder;
// Recent Order Item box target
var ulObj = $("#recentorder-list-box_"+id);
// Display error message on top
if (jsonObj.messages.error.length >0) {
var pdObj = $("#productError_"+id);
var tplHTML = $("#ErrorPageTemplate").html();
for (key in jsonObj.messages) {
var re = new RegExp("%"+key+"%", "g");
tplHTML = tplHTML.replace(re,jsonObj.messages[key]);
}
pdObj.append(tplHTML);
$("#productError_"+id).css("display","block");
}
// have recent order
if ( dataObj && dataObj.length > 0 ) {
for ( var i=0; i<dataObj.length; i++ ) {
var tplHTML = $("#RecentOrderFrontTemplate").html();
// date
var re = new RegExp("%created_at%", "g");
//tplHTML = tplHTML.replace(re,dataObj[i].order.created_at);
tplHTML = tplHTML.replace(re,dataObj[i].order.created_at_localetime);
// update id
var re3 = new RegExp("%id%", "g");
tplHTML = tplHTML.replace(re3,dataObj[i].order.id);
// update rid
var re4 = new RegExp("%rid%", "g");
tplHTML = tplHTML.replace(re4,id);
ulObj.append(tplHTML);
// Recent Ordered Item box
var orderObj = $("#order-list-attr-"+id+dataObj[i].order.id);
} // for
}
}
And that gave me the list, provided that there was a cookie called ppmeccookie, with the value of your customerid. This cookie normally gets generated when you have done a paypal checkout before, using this paypal App.
Thanks for the help.

Related

Magento - Updating attribute IF THE OPTION changed

I really need some support regarding magento:
on this page: https://goo.gl/wTeUtG
If the option changed out of the dropdown, like from 150 Gramm to 200 Gramm, the ingredients (on this page as "Zutaten") also should be updated. But only the price is going to change not the text right into tooltip on "Zutaten".
How or where can I do this?
That's what I have tried so far:
I've created a new attribute and put it into the checkbox.phtml. This is the code for it:
<p>
<label>Zutaten:</label>
<a class="tooltips" href="#">
<img src="https://shop.ellyseidl.de/skin/frontend/base/default/pektsekye/optionbundle‌​/info_icon.gif" width="11px" height="11px" />
<span><strong>Zutaten:</strong>
<?php echo Mage::getModel('catalog/product')->load($_selection->getId())->getData('zutaten'‌​); ?>
</span>
</a>
</p>
But it doesn't change the tooltip once a option is selected
I guess you will have to do it manually with jQuery since you are using it on your page, by adding event on change on the select box with the id="attribute154" or the class="super-attribute-select".
You will have to change the text in the tooltip according to the option being selected.
EDIT:
jQuery('#attribute154').on('change', function() {
var selectedVal = jQuery(this).val();
//If you want to change the tooltip according to the selected text this is how you can get it:
var selectedText = jQuery(this).find("option:selected").text();
if (selectedVal != '') {
var ingredientsText = '';
if (selectedText == '150 Gramm') {
ingredientsText = 'Ingredients for 150 Gramm';
} else if (selectedText == '200 Gramm') {
ingredientsText = 'Ingredients for 200 Gramm';
}
//And so on
jQuery('.tooltips').find('span:first').html('Zutaten:'+' Folgen in Kürze: '+ingredientsText);
} else {
jQuery('.tooltips').find('span:first').html('Zutaten:'+' Folgen in Kürze: ');
}
});
Please have in mind that you must change the text the way you need it. I still don't know what you have to add in the tooltip, but I just tested this on your site and it works. According to the text Folgen in Kürze which means coming soon, not sure what is the text you need to update.
EDIT2:
The ingredientsText var will depend on the quantity of Gramm selected, if they are static you can enter them in the code by yourself, if they are dynamic, you will have to add them somewhere in the HTML in a hidden <div> for example and then fetch them with JS from there.

Constraining tank_auth views to a div on a web age

Hi Tank_auth & web Gurus!
I have tank_auth working with my CodeIgniter application. Currently, the login/register views of tank_auth take over the entire screen. On my website, I would like the login/register views to occupy a div that I define. For example, I want the login/pw fields to just appear in the top right corner and not take over the whole screen...Can you point me in the right direction? - I read somewhere that I'd have to somehow constrain the view in a div but for the life of me I did not understand how!
Much obliged,
Mmiz
Create div for the login. Create a view for the login. Populate the div with a javascript call to the view.
<?php
//controller
//users.php
class Users {
//...
public function div_login()
{
$this->load->view('div_login_view.php');
}
//...
//------------------------------------------
//view
//div_login_view.php
echo form_open('users/login');
echo form_input('username');
echo form_password('password');
echo form_submit('Login');
echo form_close();
//------------------------------------------
//index page (or whatever page you want the form on)
<div id="login_div"></div>
<script type="text/javascript">
$(document).ready(function(){
var login_form = $.get('/users/div_login');
if (login_form.status === 200){
$('#login_div').html(login_form.responseText)
}else{
alert('There was an error getting the login form.');
}
})
</script>

Google style page loading , Bulk records not on onload, display some and fetch remain in back?

I'm developing a web application,after login the user is redirected to the inbox page,
where he will find many widgets, each with hundreds of records.
So it is taking too much time to open inbox page after login success.Very much performance issue.
So i want to display some(5-10) records in each widget
and after the page loads in the backend(user doesn't know) the request will be processing still and fetch the records and append them to the widget records.
Eg. If you open google images and search for cricket, it will display the page with images and if you scroll down only you will come to know the ajax request going and appending the response to the web page,
But it is not waiting till the entire page is loaded.
I must develop my application in the same way.
Any idea is Highly Appreciated and sample code too.
This should work for you, Mr.Chowdary.
You would need something to handle your requests in the backend. Since you did NOT specify whether you used Java or PHP or Python or whatever, I used PHP - its what I know best :D
PSEUDO CODE (loadmore.jsp)
Begin
widget = URL(widget) //the widget id or name
page = URL(page) //the page being retrieved
switch (widget)
{
case "widget1":
data_for_widget1 = paginated_query1(page)
print data_for_widget1
break
case "widget2":
data_for_widget2 = paginated_query2(page)
print data_for_widget2
break
default :
print "Invalid Widget"
break
}
End
PHP Version
<?php
if (isset($_GET['page'])) {
$widget = $_GET['page'];
$page = $_GET['page'];
switch ($widget) {
case "MyWidget1": //dynamic example
$manyManyItems; //A massive array of items
$pages = array_chunk($manyManyItems, 5); //break it up into chunks of 5 items
if( array_key_exists ($pages[$page]) )
for ($i = 0; $i < count($pages[$page]); $i++) { //load those chunks
echo '<div class="item">'.$pages[$page][$i].'</div>';
}
else {
echo "zero"; //code word that tells ajax that there is nothing more to load
}
break;
case "MyWidget2": //manual example
if($page==1) { //loads the first chunck manually
echo '<div class="item">dynamic content 1</div>';
echo '<div class="item">dynamic content 2</div>';
echo '<div class="item">dynamic content 3</div>';
}
elseif($page==2) { //loads the next batch
echo '<div class="item">dynamic content 1</div>';
echo '<div class="item">dynamic content 2</div>';
echo '<div class="item">dynamic content 3</div>';
}
else
echo "zero"; //code word that tells ajax that there is nothing more to load
break;
default:
echo "zero"; //code word that tells ajax that there is nothing more to load
}
}
?>
HTML
Each widget could look like this
<div id="MyWidget1" class="widget" data-widgetPage="0">
<div class="item">default content</div>
<div class="item">another default content</div>
...
<div class="loadmoreajaxloader" style="display:none;"><center>Loading...</center></div>
</div>
Javascript
<script type="text/javascript">
$(".widget").scroll(function()
{
if($(this).scrollTop() == $(this).height() - $(this).height())
{
var nextPage = eval($(this).attr("data-widgetPage") + 1);
$(this).find('.loadmoreajaxloader').show();
$.ajax({
url: "loadmore.php?widget="+$(this).attr("id")+"&page="+nextPage,
success: function(html)
{
if(html != "zero")
{
$(this).append(html);
$(this).('.loadmoreajaxloader').hide();
}else
{
$(this).find('.loadmoreajaxloader').html('<center>No more posts to show.</center>');
}
}
});
$(this).attr("data-widgetPage", nextPage);
}
});
</script>
Success with the app.
I got to know the following answer suits my requirement from the following site.. Jquery endless scrolling

Retrieve product custom media image label in magento

I have a custom block loading products on my front page that loads the four newest products that have a custom product picture attribute set via:
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getModel("catalog/product")->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToFilter("image_feature_front_right", array("notnull" => 1));
$_productCollection->addAttributeToFilter("image_feature_front_right", array("neq" => 'no_selection'));
$_productCollection->addAttributeToSort('updated_at', 'DESC');
$_productCollection->setPageSize(4);
What I am trying to do is grab the image_feature_front_right label as set in the back-end, but have been unable to do so. Here is my code for displaying the products on the front end:
<?php foreach($_productCollection as $_product) : ?>
<div class="fll frontSale">
<div class="productImageWrap">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image_feature_front_right')->directResize(230,315,4) ?>" />
</div>
<div class="salesItemInfo">
<p class="caps"><?php echo $this->htmlEscape($_product->getName());?></p>
<p class="nocaps"><?php echo $this->getImageLabel($_product, 'image_feature_front_right') ?></p>
</div>
</div>
I read that $this->getImageLabel($_product, 'image_feature_front_right') was the way to do it, but produces nothing. What am I doing wrong?
Thanks!
Tre
It seems you asked this same question in another thread, so to help others who might be searching for an answer, I'll anser it here as well:
I imagine this is some sort of magento bug. The issue seems to be that the Magento core is not setting the custom_image_label attribute. Whereas for the default built-in images [image, small_image, thumbnail_image] it does set these attributes - so you could do something like:
$_product->getData('small_image_label');
If you look at Mage_Catalog_Block_Product_Abstract::getImageLabel() it just appends '_label' to the $mediaAttributeCode that you pass in as the 2nd param and calls $_product->getData().
If you call $_product->getData('media_gallery'); you'll see the custom image label is available. It's just nested in an array. So use this function:
function getImageLabel($_product, $key) {
$gallery = $_product->getData('media_gallery');
$file = $_product->getData($key);
if ($file && $gallery && array_key_exists('images', $gallery)) {
foreach ($gallery['images'] as $image) {
if ($image['file'] == $file)
return $image['label'];
}
}
return '';
}
It'd be prudent to extend the Magento core code (Ideally Mage_Catalog_Block_Product_Abstract, but I don't think Magento lets you override Abstract classes), but if you need a quick hack - just stick this function in your phtml file then call:
<?php echo getImageLabel($_product, 'image_feature_front_right')?>
Your custom block would need to inherit from Mage_Catalog_Block_Product_Abstract to give access to that method.
You could also use the code directly from the method in the template:
$label = $_product->getData('image_feature_front_right');
if (empty($label)) {
$label = $_product->getName();
}

Automatic update the cart on proceed to checkout is clicked

I am using magento. I want to automatically update the cart on proceed to checkout button is clicked. so that my values are saved without the effort to click on update cart. Ajax based solution is also acceptable.
I was able to "fix" it by changing the behaviour of the Checkout button.
Instead of just going to the checkout page, it submits the cart form. In order to have it redirect to the checkout afterwards, it makes sure that redirect_url is set right before the submission.
This is the code I put in template/checkout/onepage/link.phtml:
<?php if ($this->isPossibleOnepageCheckout()):?>
<script type="text/javascript">
// <![CDATA[
function updateAndGoto(url) {
var cartForm = $$('.cart form').first();
var action = cartForm.readAttribute('action');
if (action.indexOf('return_url') < 0) {
var glue = action.indexOf('?') < 0 ? '?' : '&';
action += glue + 'return_url=' + url;
cartForm.writeAttribute('action', action);
}
cartForm.submit();
}
// ]]>
</script>
<button type="button" title="<?php echo $this->__('Proceed to Checkout') ?>" class="button btn-proceed-checkout btn-checkout<?php if ($this->isDisabled()):?> no-checkout<?php endif; ?>"<?php if ($this->isDisabled()):?> disabled="disabled"<?php endif; ?> onclick="updateAndGoto('<?php echo $this->getCheckoutUrl() ?>');"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
<?php endif?>
This seems like a very poor idea. Customers have expectations about how a cart should function, especially with an update button being present. If you change that functionality so that a customer cannot see that their update was not made until they go through the entire checkout process, they may not order what they had intended, or they may not order at all. Surprising the user is almost always a bad idea.
Otherwise, short of AJAX, you'd want to make the "Checkout" button part of the same form that wraps the cart for updates.
Hope that helps!
Thanks,
Joe

Resources