Prestashop: Add products to a new cart - web-services

This is not a general problem, but I hope someone has encountered this issue!!
I have a prestashop website, and now I'm creating a mobile version of this site, using phonegap.
I connect to the site data base via the prestashop webservice.
I can add a new cart, but this cart is empty and It doesn't belong to the customer who have added a product to his cart.
I have expected to use an url like this:
http://monsite/Create_carts.php?id_product=..&quantity=..&id_customer=..
but there is not an id_product or an id_customer attribute in the cart object.
My question is how to add products to a cart and make it belong to the logged customer?

You have an order object which links to a cart object and a customer object. There is also a cart_product object which links to a product and a cart.
Database structure:
customer -> order -> cart -> cart_object.
That is how it is in the database, I have no idea how to use the API to do that as I'm searching for that myself...
It usually seems to be that you get a blank schema, populate it with the correct data and then send it in to add it to the database. You can get the blank schema with something like:
$xml = $webService->get(array('url' => 'http://my_prestashop_shop/api/carts?schema=blank'));
But as I have stated. I cant seem to do this myself. I will come back if I find the answer.

Related

nopCommerce : how to have a shopping cart pre-filled with 2 products?

Basically I want the user to land on a pre-filled shopping cart with 2 products. I see the ShoppingCartController has the AddProductToCart action. Is there a way to call successively AddProductToCart twice, and being after redirected to the Shopping Cart ?
Also on the client side, there AjaxCart.addproductvarianttocart associated with the button Add to Cart. So what is the best way to achieve a prefilled shopping cart with nopCommerce ? I am working with nopCommerce 2.65
After digging a little in the code, I have used the following modification, and it works so far :
In the project Nop.Web.Framework, in the file WebWorkContext.cs, there is a function GetCurrentCustomer who is used among others to insert first-time non-registered visitor into the DB :
// create guest if not exists
if (customer == null || customer.Deleted || !customer.Active)
{
customer = _customerService.InsertGuestCustomer();
}
After InsertGuestCustomer, I am creating some Products and adding them to the shopping cart with customer.ShoppingCartItems.Add(new ShoppingCartItem(){...});
After the visitor registers, the shopping cart is already filled, and it can then be checked out.
Any insight whether this is the right way or not ?

Emberjs linkTo doesnot update collection i.e department.find()

Learning emberjs
I am not sure if this is a stackoverflow question or git issue. So I decided to put it on stackoverflow first.
Here is my Jsbin (Open in firefox ..not in chrome as raw.github file is used)
When I click on "<- All Department" in department template which I reached after creating a new department it does navigate back to departments template
but the #each does not display the newly added department name in list.
It does show the newly added department on refreshing the browser on /departments
UPDATE
It seems that the .set() method is working but for some reason the new object created is returning the name and ID as undefined. Might be a bug with ember-model perhaps.
The best solution for the moment would be to have 2 save methods, one on the edit controller as you currently do and then adding a different save method for creating a new department.
App.NewController = Ember.ObjectController.extend({
save:function(){
var newDep = App.Department.create({name: this.get('name')});
newDep.save();
this.get('target').transitionTo('department', this.get('model'));
}
});
Here is a jsbin with the New controller added - http://jsbin.com/EVUlOyo/1/edit
End Update
It looks like when you are creating the record it is not setting the name value correctly on the object.
I changed the following -
newDepartment = self.get('model');
newDepartment.set('name',this.get('name'));
newDepartment.save();
to -
var newDep = App.Department.create({name: this.get('name')});
newDep.save();
Here is an updated jsbin also http://jsbin.com/EkEXInO/1/edit
Hope that helps and works for you.

Shopify Python API - how to search for a product

I have built a django app that is the primary store for my products. From this, I publish products to my Shopify Store. Now my django app knows first when my product goes out of stock.
Question:
What options do I have to search for products using the Python API? Can I search by Title, Variant SKU?
Is storing the generated ID while publish the only means to get a handle on the product later?
I want to do this - so that I can mark the products Out Of stock, in a batch process, for example.
Storing the product's id is the simplest way to get a handle on the product later.
However, the product API shows that you can filter products by vendor, handle, product_type, collection_id, published_status, updated_at, created_at or published_at.
The Using the shopify python API page shows how you can use these filters through keyword arguments to the find class method, e.g. shopify.Product.find(collection_id=841564295) to list products in a specific collection.
YOu can use the official shopify python API to find a product with id:
shopify.Product.exists(product.id) # => True
product = shopify.Product.find(292082188312)
For searching products with the product title, you can use GraphQL API

Django, Tastypie and retrieving the new object data

Im playing a little bit with heavy-client app.
Imagine I have this model:
class Category(models.Model):
name = models.CharField(max_length=30)
color = models.CharField(max_length=9)
Im using knockoutjs (but I guess this is not important). I have a list (observableArray) with categories and I want to create a new category.
I create a new object and I push it to the list. So far so good.
What about saving it on my db? Because I'm using tastypie I can make a POST to '/api/v1/category/' and voilĂ , the new category is on the DB.
Ok, but... I haven't refresh the page, so... if I want to update the new category, how I do it?
I mean, when I retrieve the categories, I can save the ID so I can make a put to '/api/v1/category/id' and save the changes, but... when I create a new category, the DB assign a id to it, but my javascript doesn't know that id yet.
in other words, the workflow is something like:
make a get > push the existing objects (with their ids) on a list > create a new category > push it on the list > save the existing category (the category doesnt have the id on the javacript) > edit the category > How I save the changes?
So, my question is, what's the common path? I thought about sending the category and retrieving the id somehow and assign it to my object on js to be able to modify it later. The problem is that making a POST to the server doesn't return anything.
In the past I did something like that, send the object via post, save it, retrieve it and send it back, on the success method retrieve the id and assign it to the js object.
Thanks!
Tastypie comes with an always_return_data option for Resources.
When always_return_data=True for your Resource, the API always returns the full object event on POST/PUT, so that when you create a new object you can get the created ID on the same request.
You can then just read the response from your AJAX and decode the JSON (i dont know about knockout yet).
see the doc : http://readthedocs.org/docs/django-tastypie/en/latest/resources.html?highlight=always_return_data#always-return-data
Hope this helps

django admin filter tweaking

I want to use django's admin filter on the list page.
The models I have are something like this:
class Location(model):
name = CharField()
class Inquiry(Model):
name = CharFiled()
location = ManyToManyField(Location)
Now I want to filter Inquiries, to display only those that contain relation to specific Location object. If I use
class InqAdmin(ModelAdmin):
list_filter = ['location', ]
admin.site.register(Inquiry, InqAdmin)
the admin page displays me the list of all Locations and allows to filter.
What I would like to get, is to get list of only those locations that have some Inquiries in relation to them (so I don't ever get the empty list result after filtering).
How can this be done?
You could create a custom manager for Locations that only returns Locations that have an Inquiry associated with them. If you make this the default manager, the admin will use it.
Only caveat is that you'll need create another manager that returns all Locations and use that in the rest of your app whenever you want to retrieve Locations that don't have an associated Inquiry.
The managers section in the Django docs is quite good, and should be all you need to get this set up.
EDIT:
sienf brings up a good point. Another way to accomplish this would be to define a subclass of django.contrib.admin.SimpleListFilter, and write the queryset method to filter out Inquiries with empty Locations. See https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter