New mp cart widget

Hi all,

I don't like (sorry Aaron) The widget core for the cart, and i wanna replace it with a new more simple widget.

This is the script...Really simple... it counts all products in cart and does the total...

So, it require ajax to dinamically update the totals! I've just copied the ajax-cart.js code of mp_cart_listeners, andchanghed the name of div focused, but on update, put the old widget on screen!! Why?!

here the code (for best understand):

function instead of widget class:

function widget($args, $instance) {
global $mp, $blog_id, $plugin_url;
$blog_id = (is_multisite()) ? $blog_id : 1;
$settings = get_option('mp_settings');
$current_blog_id = $blog_id;

$global_cart = $mp->get_cart_contents(true);

if ( get_query_var('pagename') == 'cart' )
return;

if ($instance['only_store_pages'] && !mp_is_shop_page())
return;

extract( $args );

echo $before_widget;
echo "<h3 class=\"widget-title\">". __('Cart', 'bh')."</h3>";

echo '<div class="byoutique_cart_widget_content">';
$selected_cart = $global_cart[$blog_id];

foreach ($selected_cart as $bid => $cart){
foreach ($cart as $product_id => $variations){
//print_r($variations);
$subtotal[$i++] = $variations['price'] * $variations['quantity'];
$object[] = $variations['quantity'];
//print_r($sub_total);
$objects = array_sum($object);
$total = array_sum($subtotal);
}
}
if(!$objects)
$objects = 0;
echo "<div class=\"byoutique_cart_container\">";
echo "<div class=\"byoutique_cart_objects\">".__('Products:', 'bh')." ".$objects."</div>";
echo "<div class=\"byoutique_cart_total\">".__('total:', 'bh')." ".$mp->format_currency('', $total)."</div>";
echo "</div>";
echo "<div class=\"clear\"></div>";
echo mp_cart_link(true, false, __('checkout', 'bh'));
echo '</div>';

echo $after_widget;
}

function instead the js file:

function byoutique_cart_listeners() {
$("input.mp_button_addcart").click(function() {
var input = $(this);
var formElm = $(input).parents('form.mp_buy_form');
var tempHtml = formElm.html();
var serializedForm = formElm.serialize();
formElm.html('<img src="'+MP_Ajax.imgUrl+'" alt="'+MP_Ajax.addingMsg+'" />');
$.post(MP_Ajax.ajaxUrl, serializedForm, function(data) {
var result = data.split('||', 1);
if (result[0] == 'error') {
alert(result[1]);
formElm.html(tempHtml);
byoutique_cart_listeners();
} else {
formElm.html('<span class="mp_adding_to_cart">'+MP_Ajax.successMsg+'</span>');
$("div.byoutique_cart_widget_content").html(result[1]);
if (result[0] > 0) {
formElm.fadeOut(2000, function(){
formElm.html(tempHtml).fadeIn('fast');
byoutique_cart_listeners();
});
} else {
formElm.fadeOut(2000, function(){
formElm.html('<span class="mp_no_stock">'+MP_Ajax.outMsg+'</span>').fadeIn('fast');
byoutique_cart_listeners();
});
}
byoutique_empty_cart(); //re-init empty script as the widget was reloaded
}
});
return false;
});
}
byoutique_cart_listeners();

I just want update products and total...Don't wanna dispaly the table of mp_show_cart('widget')

Can you help me?
Where i wrong?

  • Patrick
    • Support Monkey

    If you want a much simpler widget display, you can also do it via a bit CSS added to your theme's style-sheet. Try the following for example to get a cart widget much like the screenshot below:

    .mp_cart_contents_widget th, .mp_cart_contents_widget .mp_cart_col_thumb {
    display:none
    }
    .mp_cart_contents_widget tr, .mp_cart_contents_widget td, .mp_cart_contents_widget tbody {
    border:none;
    }

    Hope this helps! :slight_smile:

  • micdech
    • Flash Drive

    Hi Patrick,

    this help, but isn't what i want :slight_smile:

    In this mode, i obtain always the photo, the name, the quantity etc...

    I want only the numbers of objects in cart and the total.

    By the way, thank you very much for your answer

  • Aaron
    • CTO

    You are still posting to the default marketpress ajax handler, which is designed to return refreshed cart html. You'll have to setup an aditional ajax handler, or simply use a static widget that doesn't refresh when items are added via ajax.

    Note that there is a template function already for getting the item count in cart:
    mp_items_count_in_cart()

  • PC
    • WPMU DEV Initiate

    Hiya,

    Greetings of the day.

    I was doing a regular followup today and found that we missed your last post on this one.

    Are you still seeking support on this one ? Please let us know so that we can take it further and assist you on the same :slight_smile:

    Thanks for being a great community member !

    Cheers
    PC

  • Brian Purkiss
    • Smushie Pies

    Well now. This is rather embarrassing as we're at the point of coming back and asking you if you were able to solve this. Not sure why @PC dropped the ball on this one. I apologize on his behalf.

    However, helping you create a whole new widget goes a little above and beyond the scope of support we offer here.

    We have to draw a line between what is "support" and what is "custom". Think of support as helping you implement our product in any of the ways it's meant to "out of the box". Custom work would be anything additional that the plugin doesn't do by default.

    It's tricky, and believe me, we'd love to be able to code every single feature/product/customization requested, but it's not possible. We DO listen to members and plan our development according to what is most popularly requested.

    If you want to take a stab at creating a new widget we'll be more than happy to help you with any specific questions you have. For example, if you had a question about which function is needed for x, or what function x does. But beyond that, helping you build a widget, as I said, is beyond the scope of support we can offer here.

    So, if we can support you in using this plugin on your site as it currently exists, we're more than happy to do so, but if you need a custom plugin or modifications we don't have the manpower to assist on that. If you are willing to pay someone to develop this, you should take a look at the WPMU Job Board or Tweaky.

    Sorry that I could not be of further assistance. If you have any other questions please don't hesitate to ask. We're happy to help!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.