I am using Djnago-oscar for Solar energy equipment based eCommerce site. I need to add an option to "Basket" model with "Battery Name", "Notes" and
"Manufacturer". There is a reason I don't want to add it in subclass AbstractProduct. Rather I want to built it with subclass Basket model.
Now I need help to understand my workflow to make this work with AddToBasket form. In Django-oscar/basket there are formsets.py using formset factory and a form.
I am a bit confused and decided to get help from community.
Following is the code:
models.py
MANUFACTURERS = (
('UPS SYSTEMS', 'UPS SYSTEMS'),
('VOLTA', 'VOLTA'),
('TOSHIBA ', 'TOSHIBA '),
)
BATTERIES = (
('LITHIUM', 'LITHIUM'),
('NICAD', 'NICAD'),
('NIFE ', 'NIFE '),
)
class AddBattery(AbstractBasket):
battery_name = models.CharField(max_length=1, choices=BATTERIES)
manufacturers = models.CharField(max_length=1, choices=MANUFACTURERS)
price = models.DecimalField(decimal_places=2, max_digits=6)
notes = models.CharField(max_length=200, null=True, blank=True)
def __str__(self):
return self.battery_name
class Basket(AbstractBasket):
add_bat=models.ForeignKey(_(u'Add a Batter'), to=AddBattery, null=True, blank=True)
forms.py
from django import forms
from django.conf import settings
from django.db.models import Sum
from django.utils.translation import ugettext_lazy as _
from oscar.forms import widgets
from oscar.apps.basket.forms import BasketLineForm as CoreBasketLineForm,\
SavedLineForm as CoreSavedLineForm, BasketVoucherForm as CoreBasketVoucherForm,\
AddToBasketForm as CoreAddToBasketForm
from .models import AddBattery
from oscar.core.loading import get_model, get_classes
Line = get_model('basket', 'line')
Basket = get_model('basket', 'basket')
Product = get_model('catalogue', 'product')
class BasketLineForm(CoreBasketLineForm):
class AddBatteryForm(CoreBasketLineForm.Meta):
model = AddBattery
fields = ['battery_name', 'manufacturers', 'comment']
views.py
I need help to figure this part because it has so much nested elements and I couldn't get it right.
Help is much appreciated.
Templates:
I can work this out because I need admin to have ability to add it but end user only will have an option to select from with price.
Upon selection by client I need to have consolidated price with products and plus the battery. Any advise for this part would be great as well
about how to get consolidated price from both in cart for checkout.
Don't add your fields in Basket model. You need to subclass Line model instead.
Subclass forms.py and formsets.py. You only need to change BasketLineForm, SavedLineForm and AddBasketForm. After you subclass these in your own forms. Leave rest of the Forms.
Subclass BaseBasketLineFormSet and BaseSavedLineFormSet in your own formsets edit as per your need.
Subclass BasketView and AddBasketView by supplying the forms, formsets and args/kwargs you added.
Copy template directory from app to your own folder and add form at basket_total.html as you mentioned above as the last part.
But having said that...its against the workflow as explained by others. There is no limitation at all for you in any case as far as programming is concerned. But you should always consider the most reasonable path to solve your problems.
This is a very broad question with several different components. I can offer the following suggestions for you to look into:
Doing this in the basket model is almost certainly not going to serve you well, because you will not be able to pass this custom information to the order object when it is created. More importantly, what you're trying to do doesn't seem to be a basket issue, just a product/variant issue (see below).
There are two possibilities I can see from what you have described:
a. A battery is a separate product that the user buys along with the main product. It has its own pricing and availability.
b. A battery isn't a separate product, it's just one of a fixed set of choices that a customer has when buying the main product.
If (a), then you just need to have separate products, and some logic that allows a user to select the accessory product (battery) at the same time as the main one, and that adds both to the basket simultaneously.
If (b), then these are essentially variants where one product has multiple variations with different pricing. In this case you should use Oscar's built-in support for variants.
In any case, modifying the basket model will cause you a lot of problems IMO.
I want to create an import from a CSV but i can't modify the CSV file.
So i need to define default values for a couple required fields in Magento (like "type" ( > Simple Product ) etc.
I'm looking at https://stackoverflow.com/a/7319214/2252078 to make a custom Adapter and that inject the missing required values in the array before saving.
But i already get an error that says:
Method "parse" not defined in adapter spaanproductions_basics/convert_adapter_product
So i can't even begin with my custom code.
Maybe someone has a beter idea how to create some default values, or how to fix this issue.
Magento version: 1.9.1.1
Thanks in advance.
Kind regards,
Sonny
Not sure what the problem is, your code does seem to be valid. You could try http://pastebin.com/vxewc0Zt . OR temporarily rename your app/code/local/Spaanproductions/Basics/Model/Covert/Adapter/Product.php to verify wetter the right class is actually being loaded although I highly doubt that's the problem
-- Edit (See comments) --
try changing spaanproductions_basics/convert_adapter_product to basics/convert_adapter_product your models are defined under basics, not under spaanproductions"
At the first you have to export products as a csv file to catch the structure and then modify that as you need.
Take a look at this answer, it could be useful:
Update Magento products with multiple images
I try to import an image to a Podscms custom content type 'blank slate' table.
I have already created it, and want to import data via a CSV file. I have already uploaded the images, so I thought I can provide only the imagelink and it would be good to go. However, no.
Look at some code:
CSV:
My image; http://www.example.com/wp-content/uploads/image.jpg
Code to import, found in the Pods.io docs, and my question I also found in this unanswered github request: https://github.com/pods-framework/pods/issues/1530
PHP:
<?php
$api = pods_api('images');
$api->import($csvFile, false, 'csv');
?>
I get an error that the image not is found. I think I need to provide an array via CSV.But I cannot found anything about the format for that.
It appears as though you're using a semicolon instead of a comma as your separator.
I intend to import categories into my magento from csv file. I use ValueRemapper of magmi. The Replaced Attribute is categories. And the New Values for categories is
{{ ValueRemapper::use_csv('C:\xampp\htdocs\magento\var\import\category_ids.csv')->map({item.categories) }}.
But when I run the import I get errors
SQLSTATE[HY093]: Invalid parameter number: no parameters were bound....
I tried to change the path to the csv file both with absolute and relative path, but it still has the same error. Could anyone give me a clue what the real problem of my setting? And any solution would be appreciated. Thank you.
you seem to be missing } here:
->map({item.categories)
Try:
->map({item.categories})
Currently I'm strugling with the valueremapper option within the value replacer plugin of MAGMI. Somehow he get's the item id from my current column(Category_copy), but it does not map it to the correct value in the corresponding csv located on my website. (remapcategories.csv). It seems that he is not using the csv.
My case:
I create a new field category_ids. And as a value I put in:
{{
ValueRemapper::use_csv('http://mydomain.com/remapcategories.csv')->map({item.Category_copy})
}}
My csv file looks like this. There is no markup, no quotes and no heading (just like the magmi manual suggests)
HARDWARE|LAPTOPS;3
SOFTWARE|GAMES;5
I'm getting the following error message while uploading:
Invalid category ids found for sku 718037780566:HARDWARE|LAPTOPS
It seems that it does get the value from the Category_copy, but it won't map it to "3".
Any experienced magmi user who can help me here?
You should use "/" instead of |
Also do not use absolute path for your CSV
hope this helps