Spartacus perform search without updating the products in product list page - spartacus-storefront

We have a custom filter functionality which involves adding filters in bulk and applying them at the end. For this, every time a user clicks a breadcrumb, a search call will be performed to update the current list of facets but without updating the product list on PLP. The PLP will be updated only when the user clicks ‘apply’.
The search call needed to update the facet list is done at the moment trough a http call to the search endpoint but is there a better way to do this to benefit more of spartacus (in terms of caching for example)?
Should all the layers of the backend communication be extended for this?
The current spartacus version is 3.3

Related

Shopify - Validate cart items at checkout?

A product in my store (e.g. a fine art print) has a base price of £20 and it has multiple customizable options (size / framing) that are added as additional items to the cart (e.g. Small [£0] / Medium [+£10] / Large [+£20] or Unframed [£0] / Framed [+£10] )
I have to do it this way because some products have more than 3 variant options (Shopify only supports 3)
These additional items that represent the customization options for the base product are added when the customer adds the base product to cart, but the additional products representing options are hidden to the customer in the cart.
At checkout however all is revealed, the base product appears with 2 additional items along with their additional prices. Not ideal but OK!
However, it occurred to me that there's nothing stopping a tech-savvy nerd from grabbing the variant ID of the additional items and sending a POST request to /cart/update.js that removes them from the order during checkout.
The customer just reloads the checkout page and they've just halved the price they have to pay!
I need to prevent this from happening.
I don't suppose there's a way to validate all the items in the cart when the customer requests the checkout page?
If that's not possible, how do other Shopify stores get around this issue?
If you are on the Shopify Plus plan there are two things you can do:
During checkout validation - use Script Editor to check the cart contents and if it's invalid, set the base product quantity and additional products to 0. This will prevent customers from checking out.
Post checkout validation - use Shopify Flow to cancel the order after it's placed and if it's invalid
But that's a lot of development, especially when you are not familiar with it, it will be hard to go through and make it work as expected (covering all edge cases). It's possible to create a such script but analysis of all possible scenarios and writing a code for it will take some time. If I were you I would consider an app that creates bundles as a single item. Adding such a bundle to the cart takes a few seconds to process as the app is making some admin API calls in the background but it solves your problem. I cannot promote any paid solution on StackOverflow but you will easily find something - there are plenty of solutions in the app store.
The decision comes down to your estimation + possible change requests and fixes vs. the cost of the app on a yearly basis

Cancel fetch in react admin

We are using React-Admin v4, and some of our APIs are quite slow. We're using the search input field, and our problem is that api requests can overlap. If there is an existing fetch in progress, typing again doesn't cancel the existing fetch. It fires another one, and the results list is updated when each request returns, leading to confusing UI.
Can we configure the search field to cancel existing fetches when a new one is triggered?
React-admin doesn't implement Query Cancellation, although its underlying data fetching library, react-query, does allow it (see https://react-query-v3.tanstack.com/guides/query-cancellation for details).
So if you want to implement query cancellation in a react-admin filter, you'll have to build your own component based on react-query's useQuery hook, and populate a ListContext with the results. Check the Building a List View By Hand tutorial for guidance.

Extend Spartacus NGRX Store with additional data

For our Spartacus project, we need to introduce additional Data properties in the checkout:
We have the case, that the user needs to select a delivery mode per product.
In an ideal world, upon selection, the selected delivery mode would be saved in the NGRX Store and also in the Backend to stay within the principle of the data binding defined here: https://sap.github.io/spartacus-docs/connecting-to-other-systems/#component-data-binding
Expected Data / User flow:
User goes to Checkout and to Delivery Mode Step
Custom OCC Call is made to load the supported delivery modes for each product (depends on product type and further customer specific logic)
The cart items are displayed, enhanced with a dropdown containing the available delivery modes
The user selects a delivery mode
The selected delivery mode is stored on the cart entry within the NGRX Store and saved in the backend
The new Cart totals is calculated based on the costs of the selected delivery mode
The new Cart totals is stored on the cart within the NGRX Store and saved in the backend
The user clicks on continue to get to the Review Order Step
The cart items are listed with the previously selected delivery mode
After some analysis of the existing code, we found a property deliveryMode on the orderEntry. This does not seem to be used anywhere in spartacus, but could be used to make Step 9 work by following this stackoverflow answer and this one.
Questions regarding this flow:
How can we extend the NGRX Store? We assume, it would be possible to just extend the facade (Active Cart Service), bypass the store and save the information in the backend (Described here) and afterwards refresh the store from the backend. Is that Assumption correct? If yes, that feels awkward though, as we need to reload the whole store just to contain the new property deliveryMode on the orderEntry
How can we hook into the price calculation of the cart totals to update the total based on the selected delivery mode? And again, how can we bring the new total sum into the store?
There seem to be several Answers within the Slack Channel without very few usable answers around extending the ngrx store, even though for us, it seems to be a quit normal task.. :-/
Any thoughts, inputs or support would be very appreciated. :-)
This seems like a difficult thing to accomplish seeing as delivery modes per product aren't supported as-is in spartacus. But some ideas:
You can extend core CartEntry classes (adapter, connecter, facade, etc.) to include the delivery mode for entries added to the cart. You will probably need to change all to include the delivery mode setting(s). All of these are exposed so you can modify them as needed including the store.
Utilizing multiple carts to have a product per cart and set delivery mode that way. But this would be cumbersome in my opinion.
As far as price calculation goes, I'm assuming OCC calls return total prices. Does the call for the cart entries include delivery mode costs per entry?
We have implemented the following work around and it works so far:
Enhance the Cart Model in the backend
Add new Endpoints to load the available delivery Modes per Product (by bypassing the NGRX Store)
Add new Endpoints to save the selected Delivery Mode (by bypassing the NGRX Store)
After Save Endpoint, a cart Reload is triggered, which loads the new cart totals having a custom property on the order entry (via type augmentation) into the store from the backend
It's already a lot of years past since Spartacus project started, but looks like it's still really raw projects. Spartacus is not ready to deal with real word customer's requirement and complexity of customize it quickly grow at real project(so you start to think do we really need it, as it's so unflexible at some dimentions). Some parts is really hard or not possible to customize, so you begin to search a workarounds(This question is one common case).
I think NGRX Store is one of the biggest pain in the ass to customize something at Spartacus. 2 years past and nothing changed by Spartacus team...

Passing data to shopify product/cart from a custom page

I have made this page https://tns.webwars.eu. This is a form that creates a skymap in away by filling the fields and then posts the data to https://the-night-sky.com/cart. I am using the cart.attributes feature at the moment but this applies for the whole cart and I want individual data for each item. Eg. If someone tries to add another map with different information.
Is there another way to pass the field values to the cart and therefore to checkout and confirmation email?
Thank you in advance
You should use Line Item Properties as described in good detail here: https://help.shopify.com/en/themes/customization/products/features/get-customization-information-for-products
That technique is per product, works perfect with the cart, checkout and admin, and is much easier to maintain than cart attributes.
You can use Shopify's Ajax API for that purpose:
https://help.shopify.com/en/themes/development/getting-started/using-ajax-api
Shopify provides shop-owners with an Ajax API that returns JSON-encoded responses.
This Ajax API makes it possible to add items to the cart, update quantities in the cart, and fetch information about the cart, without a page refresh. With this API, you can also fetch information about a particular product using its handle.
For example, on site: https://weedrepublic.com

BigCommerce Custom Add To Cart Speed Issue

We had a developer add a custom code to certain product pages so that the user could order multiple quantities of multiple product variants all at once from one product page.
The issue is that the script takes too long to run...when you click Add To Cart it is taking 30-60 seconds or more to add all the products to the cart.
That is way too long. (see video here https://www.dipietro.biz/wp-content/uploads/2017/04/add-to-cart-slow.webm )
This is because the script is adding each product to the cart sequentially one by one instead of simultaneously.
Is this something that can be fixed?
We need the Add To Cart speed increased drastically.
I've been told that if we had access to the cart.php file that sits on BigCommerce's server we could just add some type of ajax multi array function and that would solve the problem but of course we do not have access to BigCommerce's servers.
Any help is appreciated at this point.
Thanks!
Without seeing the code, most likely the issue is that, as you mentioned, the products are being added to the cart sequentially, while also waiting for each individual add to cart request to finish before beginning the next - that is, it will add a product to the cart, wait for that product to successfully be added, and then proceed to add the next product to the cart.
Each 'add to cart' action is an individual POST request to the cart.php file. There is a challenge here in that BigCommerce will block the requests if too many of them occur within a certain time period; this is a BigCommerce security feature.
While you do not have access to the cart.php file, and while I do not know the specifics of the BigCommerce rate-limit/security feature, the best way to approach this is to determine and set a feasible max number of concurrent requests as well as a necessary cool-down period in order to maximize the number of requests to BigCommerce while also satisfying the security/rate-limit limitation.
For example, you might set up the program to concurrently add 3 products to the cart, wait 1 second, and then proceed to add another 3 products. Does this make sense?