Restore purchase using com.logicallabs.inappproducts - titanium

How do you restore a purchase using: com.logicallabs.inappproducts? I have been messing around with this all afternoon. I can purchase a product and restore it as if I were to buy it again, but can't figure out how to directly restore it.

You can get a list of purchased products with this:
InAppProducts.addEventListener('receivedPurchases', function(e) {
e.purchases.forEach(...
});
InAppProducts.getPurchases();
Then when you find the product you're trying to restore, execute the same code that calls when you purchase it.
Found in docs: http://docs.logicallabs.com/titanium-modules/in-app-products/android/modules/Readme.html

Related

Issue with page_info and products.json

I'm a developer working on a private app to manage the database and the inventory of a Shopify Online Store with Symfony and I'm looking for getting all products or inventory of the store.
I tried with the url https://{{api_key}}:{{password}}#{{shopify_domain}}/admin/products.json , but it gets only 50 to 250 products and there's more than 200 000 products on this online Store. I also tried with /admin/inventory_items, but it returns missing or invalid parameter.
Recently, I checked the documentation of cursor-based pagination and I saw that there's a parameter call page_info but I didn't know how to get it. So after many researches, I learned that I had to find the parameter on the last product displayed to go to the next product which will be on the next page. I also seen that there was a parameter on GraphQL which is called storefrontId, it looked like page_info so I tried to add it to the URL but it didn't worked. I noticed that there were a = to the end of the URL, so I tried it with =0 =1 =2 and =3, also with =rel=next =next and =page=2 but it returns the same error : { "errors": { "page_info": "Invalid value." } }
For people who will find me a solution with downloading data and uploading it daily, this is not relevant because on this online store there is more than 200 000 products and the employee aren't developer.
If there is a possibility to update and display the database in real-time, without uploading a file, it would be perfect !
If you know how to help me, I'm open to suggestions !
Thanks,
Karim HADJ-ABDELKADER
The parameter page_info should be unique ID and not just number, look at this docoment about the pagination paramenters
https://shopify.dev/docs/api/usage/pagination-rest#parameters
for example :
https://{shop}.myshopify.com/admin/api/2019-07/products.json?page_info=hijgklmn&limit=3

Shopify Scripts - New Line Item

I would like to add a new product (line item) via Shopify Scripts when a user uses a discount code. Is it possible?
if Input.cart.discount_code && Input.cart.discount_code.code == "first10"
Input.cart.line_items << LineItem.new(variant: 24665166184512, quantity: 10, source_indices:false,grams: 0, properties_was:false, properties:false, line_price_was:false, line_price:50, original_line_price:50, discounts:0, adjustments:nil)
end
Output.cart = Input.cart
And I have error:
[Error] undefined method 'id' for 24665166184512
shopify/std_lib_mutable/core/resources/line_item.rb:164:in LineItem.to_hash
shopify/std_lib_mutable/core/resources/cart.rb:43:in Cart.to_hash
shopify/std_lib_mutable/cart_line_items/output.rb:4:in #<Class:0x7f85471e6280>.to_hash
shopify/std_lib_mutable/cart_line_items/output.rb:4:in #<Class:0x7f85471e6280>.to_hash
shopify/std_lib_mutable/core/script_kernel.rb:12:in Object.prepare_output
(prepare_output):1
Unfortunately you cannot add products to a cart using Shopify Cart Scripts.
Cart scripts can only see and handle items that are already present in the cart.
as mentioned in comments, you can delete an item because it already exists in the cart.
My advise is to use either of these methods.
1) discount codes that when someone buys something they get another product at a certain price or free.
2) create an Ajax API script that when an item is added to the cart it looks up what items are in the cart and if the item is found then adds the free item or discounted item to the cart.
https://help.shopify.com/en/themes/development/getting-started/using-ajax-api
3) (PAID OPTION) is to have a look in the app market place and you can find a few different apps available to help you with this. this one looks like it might help you? https://apps.shopify.com/special-offers

odoo auto publish product

I'm trying to build an automation rule in Odoo 11 (enterprise) so my products can publish and unpublish on the website automatically.
We sell seasonal products, roughly 17.000, and we do a lot preparation in advance.
So with "scheduling" (un)publish a product, we can save a lot work and automate this job.
So far with all my attempts, it's not working.
I have created 2 custom fields for model product.template:
x_publish_start and x_publish_end
I have created an automated action with trigger condition "based on timed condition" and apply it to products where x_publish_start is SET (not empty).
Trigger date = x_publish_start
In the data to write, I have set the default field visible on website = TRUE
Basically, this should work?? But it's doing nothing in my end.
The condition is quite basic:
if today() >= x_publish_start -> publish product
if today() >= x_publish_end -> unpublish product
screenshot
http://sharing.codeagency.be/0c0d7512e9f9
Anybody who knows what is wrong with my concept and automation, or can provide a working code example?
Thanks!
Those actions get triggered when editing a record (see action to do: update the record). What you need is more a cron that runs every day (or hour, minute...) and publishes/unpublishes products that match (or not) current date. The model you're looking for is ir.cron.

Stacking Discount Codes in Shopify

I am trying to apply Two Discounts in Shopify cart. I read the documentation and I found out that you can do the same by Using Scripts App provided to Shopify Plus Accounts. So, I went ahead and created a Discount Script. The script executed perfectly after creation in the Shopify Console. But, when I tried to do a preview it did not seem to work as by default a discount was not applied to the cart.
Secondly, after creating the Script it provided me a ruby script. I also don't know where to place it. I mean i may be missing that part as a result of which i am not getting default discounts applied to the cart. Below is the auto-generated ruby script:
DISCOUNTS_BY_QUANTITY = {
10_000 => 20,
1_000 => 15,
100 => 10,
10 => 5,
}
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
quantity, discount = DISCOUNTS_BY_QUANTITY.find do |quantity, _|
line_item.quantity >= quantity
end
next unless discount
message = "#{discount}% off when buying at least #{quantity}."
line_item.change_line_price(
line_item.line_price * (Decimal.new(1) - discount.to_d / 100),
message: message,
)
end
Output.cart = Input.cart
My Question is:
How can I implement stackable discounts in Shopify?
What is the use of the autogenerated code in the Scripts Editor and how to use it?
I asked this question quite a long time back and coming back again as i have a fair idea how shopify scripts work now. The script is executed everytime on checkout page and if a condition is satisfied then it will execute as per the code written. Below is an example where 10% OFF shipping has been provided to a user who has been tagged as a Platinum User.
customer = Input.cart.customer
if customer
customer.tags.each do |tag|
next unless tag == 'Platinum'
Input.shipping_rates.each do |shipping_rate|
shipping_rate.apply_discount(shipping_rate.price * 0.10, message: "Discounted shipping")
end
end
end
Output.shipping_rates = Input.shipping_rates
The Shopify Script app is a very powerful tool and can be used to provide really good customization to a Shopify Store. The documentation provided for the App also is very explanatory and should help one out if you want to code this on your own.
Documentaion Link - Link
Update:
Seems shopify scripts are now only available to Shopify Plus customers. This answer likely would not help customers who do not have Shopify Plus.

Shopify API CARTS - Changing line_item line_price for price Override

Shopify has a CARTS api but it is read-only. I am trying to find a way to manipulate the line_item's line_price or price attribute. Shopify support has directed me here for an answer.
Since there is no proper documentation on this any help would be appreciated.
Products have variants, and a line item has a product ID and a variant ID. A line item has a price too. And no matter how you access that item (using the Ajax API or the backend API) you cannot manipulate the price. If you want to change a price, you have to change the product's variants price. That you do with the backend API and the product or variant calls.
You can't directly manipulate the price of a line item in a cart. As you mentioned, the Carts API is read-only. That's all there is to it.
Yes you can!
Dont mess the people, you can do everything you want with your store.
You can do it via JavaScript, this is some related code i have used:
//update price when changing quantity
function updatePricing() {
jQuery('#quantity').val(jQuery('#choose-select-value option:selected').val());
var quantity = jQuery('#choose-select-value').val();
var unitPriceTotal = jQuery('.product .total-price').text();
var totalPrice = unitPriceTotal * quantity;
jQuery('.product .price').html().replace(regInput ,totalPrice);
}
This is just a way to help you go to the right place...
But please, people dont mess if you dont know something, its your store and you can do anything....
I hope this helps to you to find the way.