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

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 ?

Related

How to get Zomato restaurant ID using restaurant link?

I want to get details of a restaurant in Zomato. I have it's link as the input (https://www.zomato.com/mumbai/fantasy-the-cake-shop-kalyan?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1). By browsing the documentation of Zomato APIs, I didn't found a way to get it.
I tried searching for the restaurant using search API but it returns many results.
Any help will be appreciated
It's a two-step process:
Find out restaurant's city id, in your case, Mumbai's city id through the /cities API. It's a simple query search.
Use the city id from the above API call in the /search API, like, https://developers.zomato.com/api/v2.1/search?entity_type=city&entity_id=3&q=fantasy%20the%20cake%20shop%20kalyan
This would give all the basic information about a restaurant.
View the page's source and search for window.RES_ID
I had the same issue as you described. This Zomato's API approach is at least odd. It's almost immposible to GET any information about restaurant if you don't know res_id in advance and that's not possible to parse since Zomato will deny access.
This worked for me:
Obtain user-key from Zomato API Credentials (https://developers.zomato.com/api)
Search restaurant url via API (https://developers.zomato.com/api/v2.1/search?entity_id=84&entity_type=city&q=RESTAURANT_URL&category=7%2C9). The more specific you will be, the better results you'll get (This url is specified by city to Prague (ID = 84) and categories Daily menus (ID = 7) and Lunch (ID = 9). If there is possibility do specify city, category or cuisine, it helps, but should't be necessary. Don't forget to define GET method in headers.
Loop or filter through json results and search for the wanted url. You might need to use method valueOf() to search for the same url. Be careful, you might need to add "?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1" at the end of your wanted url so it has the same format. Check that through Zomato API Documentation page.
for (i in body.restaurants) {
var url_wanted = restaurant_url + '?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1'
var url_in_json = body.restaurants[i].restaurant.url;
if (url_wanted.valueOf() == url_in_json.valueOf()) {
var restaurant_id = body.restaurants[i].restaurant.id;
}
console.log('Voala! We have res_id:' + restaurant_id);
}
There you have it. It could be easier though.
Hope it helps!
once you have the url of the rseraunt's page you can simply look for a javascript object attribute named "window.RES_ID" and further use it in the api call.

How to show a list of registered users in Joomla?

I have hundreds of registered users. Those are grouped in different user groups:
See screenshot below (I changed this a little bit to protect my customers site):
Registered -> Teachers
Registered -> Students
How can I show a list of 'Teachers' online?
I want to list up all those teachers in a table or list, so that other teachers see this information.
Thank you. Any information is welcome.
You can use the following for to get the usernames from a specific user group:
$teachers = JAccess::getUsersByGroup(2); //change number in the brackets
$students = JAccess::getUsersByGroup(8); //change number in the brackets
foreach($teachers as $user_id) {
$user = JFactory::getUser($user_id);
echo $user->name;
}
foreach($students as $user_id) {
$user = JFactory::getUser($user_id);
echo $user->name;
}
Change "2" and "8" to the ID's of the Teachers and Students user groups.
Hope this helps
Personally, I think the best way to do that is to create a contact category teachers and then link each teacher to a contact record.
You can make a list of users in a group (there's even a method JAccess::getUsersByGroup() but I don't think it's that useful for this purpose. http://officialjoomlabook.com/school25/staff-directory is an example of where I did what I am suggesting.

Prestashop: Add products to a new cart

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.

Same random record across website

I am building a website that shows a different background every time a user enters it. This background is then used across the website with the same user and session.
So basically, a user entres the homepage, gets a background and that image won't change until the user closes the website or opens up a new page. I think you understand what I mean.
I know how to get a random record from the database using Django, but I'm not sure how to keep that record persistent across the website, because if I pull it on every view, I'll get a different image on different pages.
So my "index" view could be calling
bgimage = BackgroundImage.objects.random()
But then I have a problem. How can I get this random record unchanged across all the other views. Is that possible? Should I be looking into sessions, cookies?
Thank you!
you could use sessions - something like
if 'bgimage' not in request.session:
bgimage = BackgroundImage.objects.random()
request.session['bgimage'] = bgimage.pathtoimage
Context processor:
def bgimage(request):
if 'bg_image' not in request.session:
image = BackgroundImage.objects.random()
request.session['bg_image'] = image.file
return {'background_image' : request.session['image']}

Django Inline Autocomplete

Is it possible to filter an inline autocomplete field by a dynamic value entered by a user?
For example, I have a an admin form where staff enters games information including home and visiting team, game date and time, score, etc. They also enter individual player names and stats. I would like to add a filter to show only the players on either the home or visiting team.
I am using the InlineAutocompleteAdmin module, which provides autocomplete hints for input fields.
Here is the current inline autocomplete code:
class IndividualFootballGameInline(InlineAutocompleteAdmin):
model = IndividualFootballGame
extra = 1
related_search_fields = {
'player': ('player__first_name', 'player__last_name', '#team__sport__sport=Football', '#team__season__season_start_date__year=' + str(get_current_season_start_year('football'))),
}
If this can be accomplished, can you explain how?
InlineAutocompleteAdmin provides a template that I modified to provide this functionality. The file templates/admin/autocomplete/inline_searchinput.html defines the jQuery lookup() function. I added additional code to check for values in the visiting and home teams field, and to append them to search_fields as needed.