I need to add a packaging fee for 2 specific products and I would like this packaging fee to be multiplied by the cart item quantity…
Any idea on how I can manage this?
Thank you in advance.
M
Adding some code to help see what you want to make would be useful. Assuming you set this up in a Django web server, you would be able to save the product costs to variables and compare them to the product in the cart. For example:
cart = [] #we make cart empty list
cart1item = 'Example1'
cart2item = 'Example2'
specificproduct1 = 'specific1'
specificproduct2 = 'specific2'
if specificproduct1 or specificproduct2 in cart:
specificproduct1.append(card).len()
specificproduct2.append(cart).len()
Best Of Luck!
Related
I looked everywhere.
I have Opencart 2.0.2.0. Some of my products are vegetable. So for them I want to insert 1kg price and give an input field for customers to enter the weight they are after. So 1kg is $29 and if the customer enters "271"g, the price should be "(29/1000)*271 = $7.85. Do you know the easiest way to implement this and pass this dynamic price?
Thanks heaps.
This OpenCart extension should be able to do it.
Want to display different prices for a same product. Multiple sellers will be selling the same product with their respective prices is what I want to display if someone views a product....
If I understand you, It's not a coding case.
1 - go to Admin/Sales/Customers/Customers Group, and create as many groups as you want.
2 - go to Admin/Catalog/Products and edit an exiting product or create a new product. in Special tab you can assign different prices for each group created on step 1.
My first thought is to make them separate products, however you might want to display a product on a single page with a list of sellers to choose from, in which case...
The different sellers are product options!
The way I have set this up is by adding fields for them in the SQL products table such as price_a, price_b, price_c and then adding another field to the customers table called price_category with the relevant prefix (A,B,C). Then I wrote a function under getProduct (catalog/model/catalog/product.php) to cater for this.
The reason I took this route is because my files are uploaded automatically to the table and links to another program which generates invoices and sends the result back to the website automatically.
My Function is as follows:
if ($query->rows) {
foreach ($query1->rows as $row) {
$price_category = strtolower($row['price_category']);
$debtor_class = $row['debtor_class'];
$price_percentage = $row['price_percentage'];
}
} else {
$price = ($query->row['discount'] ? $query->row['discount'] : $query->row['price']);
$special = $query->row['special'];
}
$product_special_query = $this->db->query("SELECT price, to_qty, bonus_qty FROM product_special WHERE debtor_class = '".$debtor_class."' AND product_id = '".(int)$product_id."' AND customer_group_id = '".(int)$customer_group_id. "'");
I have model cake, pricing. Pricing is manytomany to Cakes. Now in order model how i should store the values ?
class Order:
service = models.OneToOneField('Service')
price = models.OneToOneField('Pricing')
Since service is also linked to pricing, i cant create a order table like that.
Can somebody help out?
I don't know if I understand you question correctly, but I guess you have to state a related_name, for example:
class Order:
service = models.OneToOneField(Service, related_name='service')
price = models.OneToOneField(Pricing, related_name='price')
I have a model like this:
class MovieHistory(models.Model):
watched_by = models.ForeignKey(User)
time = models.DateTimeField(auto_now_add=True)
movie = models.ForeignKey(Movie)
I want to get up to 15 movies that were watched the most in the last 30 days. So far I have this:
Movie.objects.filter(time__gte=datetime.now()-timedelta(days=30))
How do you filter again, and order them by movie count? I know that I can filter the first 15 results like this: [:15], but I don't know how to order by the amount of movies in that model, and only pick one of each (so I don't have repeated MovieHistories with the same movies on each one).
Thanks.
Annotation is likely the best approach:
from django.db.models import Count
most_watched = Movie.objects.all().annotate(num_watched = Count('watched_by')).order_by('-num_watched')[:15]
I haven't tested this, but I believe this is on the way to the answer. Please let me know if it works! You may need to replace count('watched_by') by Count('watched_by_id') or whatever the field name is in your database (check with ./manage.py sql your_appname).
Hope this helps!
For more on using these annotations: https://docs.djangoproject.com/en/dev/topics/db/aggregation/#cheat-sheet
I have these models :
class Package(models.Model):
title = CharField(...)
class Item(models.Model)
package = ForeignKey(Package)
price = FloatField(...)
class UserItem(models.Model)
user = ForeignKey(User)
item = ForeignKey(Item)
purchased = BooleanField()
I am trying to achieve 2 functionality with the best performance possible :
In my templete I would like to calculate each package price sum of all its items. (Aggregate I assume ?)
More complicated : I wish that for each user I can sum up the price of all item purchased. so the purchased = True.
Assume I have 10 items in one package which each of them cost 10$ the package sum should be 100$. assume the user purchase 5 items the second sum should be 50$.
I can easily do simple queries with templetetags but I believe it can be done better ? (Hopefully)
To total the price for a specific package a_package you can use this code
Item.objects.filter(package=a_package).aggregate(Sum('price'))
There is a a guide on how to do these kind of queries, and the aggregate documentation with all the different functions described.
This kind of query can also solve your second problem.
UserItem.objects.filter(user=a_user).filter(purchased=True).aggregate(sum('price'))
You can also use annotate() to attach the count to each object, see the first link above.
The most elegant way in my opinion would be to define a method total on the Model class and decorate it as a property. This will return the total (using Django ORM's Sum aggregate) for either Package or User.
Example for class Package:
from django.db.models import Sum
...
class Package(models.Model):
...
#property
def total(self):
return self.item_set.aggregate(Sum('price'))
In your template code you would use total as any other model attribute. E.g.:
{{ package_instance.total }}
#Vic Smith got the solution.
But I would add a price attribute on the package model if you wish
the best performance possible
You would add a on_save signal to Item, and if created, you update the related package object.
This way you can get the package price very quickly, and even make quick sorting, comparing, etc.
Plus, I don't really get the purpose of the purchased attribute. But you probably want to make a ManyToMany relationship between Item and User, and define UserItem as the connection with the trhough parameter.
Anyway, my experience is that you usually want to make a relationship between Item and a Purchasse objet, which is linked to User, and not a direct link (unless you start to get performances issues...). Having Purchasse as a record of the event "the user bough this and that" make things easier to handle.