detail_productConfigurable parent and product context

7 views
Skip to first unread message

FranckB

unread,
Oct 23, 2009, 5:18:03 AM10/23/09
to Satchmo developers
hi there

Does someone had already played with product variation.
In product views we have only access to product this way, product =
product.productvariation. parent.product.
I need to access current variation product object in my product
template and detail_productConfigurable in order to for example
display good sku or change photo on variant, but can't find the way,
i've seen product_id = product.id, but it's not populated in
context ??

By the way, should it not be more confortable for us to use a parent
product concept in order to have in a product variation view the
followings :
- product (for the current variation product, with real variation sku,
photos, price, etc...),
- parent_product( for the parent informations with options group,
variations, etc )

This way we can do more in templates with product variations.

Does it seems logical for you, or do i have miss something in the
concept of managing product variations ?

Franck

FranckB

unread,
Nov 9, 2009, 8:21:29 AM11/9/09
to Satchmo developers
Anyone ?
Are my questions not clear ?

Bob Waycott

unread,
Nov 9, 2009, 9:01:37 AM11/9/09
to satchmo-d...@googlegroups.com
You should be able to access any product-related information via Django's related syntax for objects. 

I'd suggest pulling up /admin/docs in your store & checking through the Model docs there. You should be able to see all the attributes on a ProductVariation and walk through the various relations, which you can then translate directly to view & template queries.

FranckB

unread,
Nov 9, 2009, 2:08:11 PM11/9/09
to Satchmo developers
Thanks for your answer but the problem is not to have access to
product variations, the problem is to access the current product
variation. I can't see no other way to achieve that than alter the
core view.

To be clear a demonstration with demo data, just try to paste the
following within your detail_configurableproduct.html :
<code>
<div>
<h1>Available templates tags in Current product page</h1><br />
<h3>product_id : {{ product.id }}</h3>
<h3>name : {{ product.name }}</h3>
<h3>sku : {{ product.sku }}</h3>
<h3>slug : {{ product.slug }}</h3>
<p><strong>details : </strong>{{ details|as_json }}</p>
<p><strong>st_variations : </strong>{{ st_variations|as_json }}</
p>
<p>But what is the way to access to my current product (my current
variation) ? : {{current_product|as_json}}
</p>
</div>
</code>


Now go to (example with demo data) :
http://127.0.0.1:8000/shop/product/dj-rocks/
http://127.0.0.1:8000/shop/product/dj-rocks-s-b/

if the page your are viewing is a "model", a "parent product",
(http://127.0.0.1:8000/shop/product/dj-rocks/) you can access relative
variations via details and st_variations tags, it's ok.

But if the page you are viewing is a product variation, a "child
product", you can only access to the model informations, not the
current viewed variation. There is no way to access to the current
slug for example or simply the current object ?!? I just want to know
and display the good slug or sku but it's a pain...

How can i deal with that if i want to display photos attached to the
current variation ?
How logical is it to have one slug in url and another result if i call
the slug tag ?

By the way Is there here any problems relative to google duplicate
content seo problematic ?

I'm working on satchmo for weeks now and i admit that i was a bit
disapointed when i've found that in product/view/__init__.py (+/- line
130)
<code>
if 'ProductVariation' in subtype_names:
selected_options = product.productvariation.unique_option_ids
#Display the ConfigurableProduct that this ProductVariation
belongs to.
product = product.productvariation.parent.product
</code>

The only way i've found is to do the following but if there is a more
elegant solution that doesn't need to modify satchmo core...
<code>
# Clone product object in order to have current product variations
in context (extra_context)
current_product = product

if 'ProductVariation' in subtype_names:
selected_options = product.productvariation.unique_option_ids
#Display the ConfigurableProduct that this ProductVariation
belongs to.
product = product.productvariation.parent.product

subtype_names = product.get_subtypes()

best_discount = find_best_auto_discount(product)

extra_context = {
'product': product,
'current_product' : current_product,
'default_view_tax': default_view_tax,
'sale': best_discount,
'error_message' : errors,
}
</code>

So if someone can answer with a smart solution i'll take it !
Thank's in advance
Franck



On Nov 9, 3:01 pm, Bob Waycott <bobwayc...@gmail.com> wrote:
> You should be able to access any product-related information via Django's
> related syntax for objects.
>
> I'd suggest pulling up /admin/docs in your store & checking through the
> Model docs there. You should be able to see all the attributes on a
> ProductVariation and walk through the various relations, which you can then
> translate directly to view & template queries.
>

Ricky Rosario

unread,
Nov 9, 2009, 2:24:11 PM11/9/09
to satchmo-d...@googlegroups.com
Hello,
 
So if someone can answer with a smart solution i'll take it !


I ran into a similar problem and ended up creating a template tag in my localsite app in order to not modify the view. If you pass in product and options then you can get back to the ProductVariation. I know this isn't ideal and the view should probably give access to the actual ProductVariation, but I didnt want to change the view for this.

Regards,
-Ricky
Reply all
Reply to author
Forward
0 new messages