This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Forum Replies Created

Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • in reply to: Input quantity and stock status in vertical results #51255
    samuelepellizzarisamuelepellizzari
    Participant

    Hi Ernest,

    I am resuming this thread because, after several tests, it turns out that the quantity selector shows up but the quantities themselves aren’t actually added to cart. Whenever I “add to cart”, it’s 1 piece for each product.

    The complete code I am using is as follows:

    add_filter('asp_results', 'asp_add_to_cart_data', 1, 1);
    function asp_add_to_cart_data($results) {
        $product_add_to_cart_text   = 'Aggiungi al carrello';
        $variation_add_to_cart_text = 'Choose variation';   // Leave it empty to not display at all
        
        if (class_exists("WooCommerce")) {
            $_pf = new WC_Product_Factory();
            foreach ($results as &$r) {
                if (
                $r->content_type == "pagepost" &&
                    in_array($r->post_type, array("product", "product_variation"))
                ) {
                    $product = $_pf->get_product($r->id);
                    $is_variable = $product->is_type( 'variable' ) || $r->post_type == 'product_variation';
                    $link = !$is_variable ? get_permalink(wc_get_page_id('shop')) : $product->get_permalink(); 
                    $ajax = !$is_variable ? ' ajax_add_to_cart' : ''; 
                    $text = !$is_variable ? $product_add_to_cart_text : $variation_add_to_cart_text;
                    if ( empty($text) )
                        continue;
                    ob_start();
                    ?>
                    <div class="woocommerce">
    					<div class="quantity">
    						<input type="number" step="1" min="1" max="" name="quantity" value="1" title="Quantity" class="input-text qty text" size="4" pattern="[0-9]*" inputmode="numeric">
    					</div>
    					<a href="<?php echo $link; ?>"
    					   class="button product_type_simple add_to_cart_button<?php echo $ajax; ?>"
    					   data-product_id="<?php echo $r->id; ?>" data-product_sku=""
    					   rel="nofollow"><?php echo $text; ?></a>
    				</div>
                    <?php
                    $button = ob_get_clean();
                    $r->content .= $button;
                }
            }
        }
        return $results;
    }
    add_action('wp_footer', 'asp_add_to_cart_handler');
    function asp_add_to_cart_handler() {
        ?>
        <script>
        jQuery(function(t){if("undefined"==typeof wc_add_to_cart_params)return!1;var a=function(){t(".asp_r").on("click",".add_to_cart_button",this.onAddToCart).on("click",".remove_from_cart_button",this.onRemoveFromCart).on("added_to_cart",this.updateButton).on("added_to_cart",this.updateCartPage).on("added_to_cart removed_from_cart",this.updateFragments)};a.prototype.onAddToCart=function(a){var o=t(this);if(o.is(".ajax_add_to_cart")){if(!o.attr("data-product_id"))return!0;a.preventDefault(),o.removeClass("added"),o.addClass("loading");var r={};t.each(o.data(),function(t,a){r[t]=a}),t(document.body).trigger("adding_to_cart",[o,r]),t.post(wc_add_to_cart_params.wc_ajax_url.toString().replace("%%endpoint%%","add_to_cart"),r,function(a){a&&(a.error&&a.product_url?window.location=a.product_url:"yes"!==wc_add_to_cart_params.cart_redirect_after_add?t(document.body).trigger("added_to_cart",[a.fragments,a.cart_hash,o]):window.location=wc_add_to_cart_params.cart_url)})}},a.prototype.onRemoveFromCart=function(a){var o=t(this),r=o.closest(".woocommerce-mini-cart-item");a.preventDefault(),r.block({message:null,overlayCSS:{opacity:.6}}),t.post(wc_add_to_cart_params.wc_ajax_url.toString().replace("%%endpoint%%","remove_from_cart"),{cart_item_key:o.data("cart_item_key")},function(a){a&&a.fragments?t(document.body).trigger("removed_from_cart",[a.fragments,a.cart_hash,o]):window.location=o.attr("href")}).fail(function(){window.location=o.attr("href")})},a.prototype.updateButton=function(a,o,r,e){(e=void 0!==e&&e)&&(e.removeClass("loading"),e.addClass("added"),wc_add_to_cart_params.is_cart||0!==e.parent().find(".added_to_cart").length||e.after(' <a href="'+wc_add_to_cart_params.cart_url+'" class="added_to_cart wc-forward" title="'+wc_add_to_cart_params.i18n_view_cart+'">'+wc_add_to_cart_params.i18n_view_cart+"</a>"),t(document.body).trigger("wc_cart_button_updated",[e]))},a.prototype.updateCartPage=function(){var a=window.location.toString().replace("add-to-cart","added-to-cart");t(".shop_table.cart").load(a+" .shop_table.cart:eq(0) > *",function(){t(".shop_table.cart").stop(!0).css("opacity","1").unblock(),t(document.body).trigger("cart_page_refreshed")}),t(".cart_totals").load(a+" .cart_totals:eq(0) > *",function(){t(".cart_totals").stop(!0).css("opacity","1").unblock(),t(document.body).trigger("cart_totals_refreshed")})},a.prototype.updateFragments=function(a,o){o&&(t.each(o,function(a){t(a).addClass("updating").fadeTo("400","0.6").block({message:null,overlayCSS:{opacity:.6}})}),t.each(o,function(a,o){t(a).replaceWith(o),t(a).stop(!0).css("opacity","1").unblock()}),t(document.body).trigger("wc_fragments_loaded"))},new a});
        </script>
        <?php
    }

    Perhaps I am missing something…

    in reply to: Integration with barcode scanner #50203
    samuelepellizzarisamuelepellizzari
    Participant

    Hi Ernest,

    Sorry, but I can’t get it to work. Probably am I missing something? Here is the complete code:

    var barDataEl = document.getElementById('status');
    for (var i = 0; i < barcodeResult.length; ++i) {
    	var sBarcode = DSScanner.bin2String(barcodeResult.at(i));
    	barDataEl.innerHTML = barcodeResult.at(i).type + ': ' + sBarcode;
    
    $("input.orig").val(sBarcode).focus();
    
    ASP.api(1, "searchFor", sBarcode);
    
    }
    in reply to: Integration with barcode scanner #50196
    samuelepellizzarisamuelepellizzari
    Participant

    Hi Ernest,

    Many thanks for your reply!

    Would that trigger the ajax live search, too? That would be nice, in order not to leave the page.
    Or triggering live results would require a different code?

    Thanks again,

    Samuele

    in reply to: Filters on result page not working #48771
    samuelepellizzarisamuelepellizzari
    Participant

    I’m sorry to bother you on this, but your plugin is definitely one of the best out there and it has so far suited many specific needs of our website like no other.

    I deactivated the plugin myself, then added a standard WordPress search bar on the header. I kindly invite you to test it just another time. Let’s say, search for “tecnica” – results are here:
    https://www.musicandbooks.edizionicurci.it/ram10/?s=tecnica

    And filters show.

    I’m clueless…

    in reply to: Filters on result page not working #48763
    samuelepellizzarisamuelepellizzari
    Participant

    Hi Ernest,

    I am trying to debug this following your hints (thanks!).

    So, I rebuilt the result page in a simpler way.

    I also found that, by deactivating “Replace the default theme search with:”, the standard search works, as well as filters. However, as soon as I override it with Ajax Search Pro, the filter is gone.

    Redirection to result page overridden by Ajax Search Pro is triggered by both magnifier and return button.

    Please have a look at the screenshots attached and let me know your thoughts.

    Best,
    Samuele

    in reply to: Filters on result page not working #48755
    samuelepellizzarisamuelepellizzari
    Participant

    Hi Ernest,

    I see… The goal is to get an Amazon-like result page, that can be filtered.

    However it turns out that the issue occurs immediately on page load, as if the filters couldn’t detect the original loop, even before live loading.

    What’s odd is that if I go to the standard result page (without Ajax Search Pro overriding it), filters work. If I use Ajax Search Pro to get the results, with all the query variable appended to the URL, filters don’t show

    Is there a way to prevent that? Could it be a matter of get/post method, or other compatibility tweaks?

    Please shed some light at the end of the tunnel…

    Samuele

    in reply to: Filters on result page not working #48749
    samuelepellizzarisamuelepellizzari
    Participant

    You cannot access this content.

    in reply to: Input quantity and stock status in vertical results #48748
    samuelepellizzarisamuelepellizzari
    Participant

    Hi Ernest,

    That’s absolutely brilliant! I didn’t know CSS could do if-conditionals this way.

    I’ll try straight away!

    Many thanks,

    Samuele

    in reply to: Input quantity and stock status in vertical results #48738
    samuelepellizzarisamuelepellizzari
    Participant

    Hi Ernest,

    Many thanks for your feedback and consideration for this feature on possibly future releases.

    Regarding the strings to customize, this is what I mean: I need to show the value of the _stock_status string within the result area. However, the value is expressed in English, as per the standard WooCommerce settings: I would like to show those values (‘instock’ and ‘outofstock’) translated into Italian (the language of the website) and in two different color.

    You already implemented the conditional brackets (https://documentation.ajaxsearchpro.com/advanced-options/advanced-title-and-description-fields#conditional-bracket-examples), but they show a field’s value based on its existence. I don’t know if it is possible to show a text string based on a field’s value, e.g. if {_stock_status} = ‘instock’ then show ‘• In magazzino’ (possibly in green), if {_stock_status} = ‘outofstock’ show ‘• Non in magazzino’ (possibly in red).

    Could you please advise on this?

    Thanks again,

    Samuele

    in reply to: Input quantity and stock status in vertical results #48734
    samuelepellizzarisamuelepellizzari
    Participant

    Hi Ernes,

    It does work!

    Indeed, to make the input quantity and buttons clickable, I needed to change the result behavior (https://documentation.ajaxsearchpro.com/layout-settings/results-behavior) and uncheck “Make the whole result area clickable”.

    I am now trying to style it in order to align it on the right, just above the add to cart button.

    I encourage you to include such functions and make them available in the backend for your next major release. The same goes for stock quantities: is there a way to customize those strings?

    Many thanks indeed,

    Samuele

Viewing 10 posts - 16 through 25 (of 25 total)