How to make automatic best seller collection in Shopify - shopify

I want one of my collection to show the top 20 best selling items in my store in order and I want it to update dynamically.
No idea where to start.

Create a collection in store admin. Add all your products inside and choose "sort by best selling" option.
Loop through this collection in code to display it by setting limit:20 parameter in your forloop opening.

Use scripting code to query all your orders using the Shopify API
For each order count the products sold
Sort the result from most to least
Take top 20 products and add them to a custom collection called Best Sellers
Sit back and profit!

Related

Dynamic Variant Price while adding variant into the Shopify cart

I have Shopify Store, where customer can design/customise their product before buying it. and based on the design / customisation price of the selected variant may get varied. but I think Shopify does not facilitate to change variant price dynamically while adding into cart.
Is any solution there I might be missing ? Any help will be appreciated.
There are a few solutions none of which are great.
Quantity based
Make the product price $1 and based on the options increase the quantity in order to meet the required price. With a little code you can change the cart to look like it's a single product, but the checkout will not be OK.
Variant based
If the product will have only a few price changes you can create different variants and change the variants based on the selected options. For example 10 different variants for 10 different prices.
App based
You can use an App such as https://apps.shopify.com/product-options to create options that can modify the product price. ( this will add dummy products to the checkout as well )
For Plus, you can use shopify script to edit the line items directly.
If you're not Plus users, you have to do it on server-side, i.e. your backend
submit an ajax request on your custom product page
backend receives the request. Use admin API to create a new product variant on the fly
set the variant price, weight, quantity, or other properties based on your business rules
return response to client
client receives a successful response. use cart ajax to add the new variant to cart
let client continue checkout
Upon order is made, use webhook to update inventory or other information required. But there is a problem regarding variant limit. For each product, you can only add 100 variants.
So you need to create new products when the variant is used up for the product. Alternatively, you can delete the existing variants. But the variants in customer carts will be cleared.
I am doing something similar to what you're doing so I think our approach will be more or less the same. Basically, there are only 2 solutions, either create a new product or new discount dynamically. Both approaches create many dummy/garbage data

How do i add product option or a variant that increments the price - shopify?

I'm creating a custom feature on a Shopify theme and I need to add product options or variants that each increment a price by a certain amount.
For example, if I want to have wrapping on a product, that costs 10$ extra. I don't want to create a "wrapped" variant that costs product price + 10$, I want it to be dynamically calculated because I will be adding multiple such choices.
I then need to add the product to the cart via the Shopify AJAX API, so I will be needing to specify such added options in the request body somehow and have Shopify calculate the final price.
How would I go about doing this?
Prices in Shopify are attached to variants.
To say it simply you can't modify the price of a variant in any way. The price is set on creation of the variant and you can't modify the variant price from the front-end.
If you plan to modify the price based on the user input you need to create predefined variants for each option and change the selected variant based on the user input.
If you still want real dynamic price you will need to look for some kind of an App that will support this functionality.

Shopify - auto-tagging by 'compare at price' difference

The shopify store I edit has a 'sale' collection. This consists of products which have been auto-tagged on the condition that the 'compare at price' is higher than the actual price.
I want to create a new 'clearance' section, which would consist of products where the actual price is cheaper than the compare at price by 50% or greater. I can't find a simple way to do this (i.e. by using the inbuilt collection creator).
Can anyone help me out?
Discounts are applied at the checkout, not when browsing a product. That is why the Smart Collection logic has no conditions based on discounts. If I were you I would try and work out how to build a collection "clearance" with conditions that make sense, and then you could create a price rule/discount that would apply to that collection (50% off). It seems like that is the way to go.

Searching products using details.name and details.value using the Best Buy API

The Best Buy Search allows to search products specifying a criterion on details.name and details.value fields.
http://api.remix.bestbuy.com/v1/products(details.name="Processor Speed" & details.value="2.4Ghz")?apiKey=YOURKEY
However details is a collection. The query above actually returns all products has a detail entry named "processor" and a detail entry whose value is "2.4Ghz" but not necessarily in the same details entry. Is there a way to create a query that will return only products for which those value and name are for the same details entry ?
Unfortunately there is no way to do this unless the particular detail you are interested in has been exposed as a top level attribute (processor speed has not). To accomplish this you will need to run your query as you have described, and then comb through the results and remove the irrelevant products in your own code.

Secondary sorting in Magento

I have come across a problem which my developer says there is no solution to.
I have an ecommerce site www.lovefashion.pk roughly 800 products to date. It has categories with collections of products from a particular brand and New Arrivals and Sale pages that show a number of categories. The issue I am faced with is the way Magento displays these products on catalog pages.
We create a custom sort 'BY date' and called it 'Latest' so I would choose a date for a collection and the catalog pages would show the collection with newest sort by date first and so on. Issue is with secondary sorting now. I have products with design codes say Brand A code 1-A, Brand A code 1-B, Brand A code 2-A and so on. When creating these products, we go alphabetically like 1-A,1-B, 2-A etc.
Say a collection has 15 products and i have given all its products a sort by date of 15th April. Magento does the date sorting OK but secondary sorting i.e by product ID (oldest to newest) is what we cant find a way to implement. It shows products now with latest ID first, i.e 20-B, 20-A, 19-B, and so on till 1-A e.g http://www.lovefashion.pk/shop-by-price/
Is there a way to solve this problem? or can SQL manipulation do the trick? Will aprreicate any help
This is a very interesting question. Can you tell us a little more about what you are trying to do? I think you want the products on each page reversed, but the pages to keep the order they have, yes? or do you want the page to go 'Asim Jofa Luxury Lawn Collection 2014 / 1-A' then 'Orient Lawn Kurti Collection 2014 / 01-B' then 'Orient Lawn Kurti Collection 2014 / 01-A' and so on?
Anyway, I think all you need to do is code a secondary sorting of the collection for each page which could be coded in the list.phtml file.
Psuedo code:
get the collection sorted by date and paginated
reverse the collection
pass the collection into the existing foreach(){echo(<li>product info</li>)}
So 'reverse the collection' might be tricky. And strictly you want to sort by sku on 1A, 1B, 2A, 2B - but I'm sure your developer can figure it out.
$reversed_collection = array_reverse($current_page_collection->toArray());
might work but I think the toArray will loose all the class types so it's not the same as reversing the object.
Collections are like arrays so end($current_page_collection) and prev($current_page_collection) might work but you would have to try it (and report back if it works). In that case a simple for loop to iterate over each item of the colection.
If you are making a custom filter then really it is just a case of putting each item of the collection into an array with an appropriate key and sorting with ksort().
So it is my opinion that it can be sorted that way, but it should be done in two stages.