News:

Support the VirtueMart project and become a member

Main Menu

Attributes/Custom Fields Thread

Started by PRO, September 12, 2011, 15:02:49 PM

Previous topic - Next topic

gothamcity

Hi all,
I'm a complete Newby and like many of yours I tried for days to find out a solution to deal with the product variants in VM2 (2.0.6 exactly). I read tons of posts/threads read people attacking Milbo who is doing a great job, in my opinion.
As you see it's my firt thread, but as I finally found a solution for my shop; I loved to give somethin back to the community.

So, what was my issue?
My shop has products with different scopes of supply (e.g. you have the basic product, a shovel (set A), another option with the shovel and a spare handle (set B)).
What I wanted was
a) a drop-down in the add-to-cart area that refreshes the price depending on the option chosen
b) as my sets have different SKUs I needed the SKU to be taken into the shopping cart (and the invoice later on), as otherwise order processing would be difficult

1) Solution A: a cart variant.
(+) easy to set up
(+) price refreshes
(-) only works with extra price for the option (so, e.g. Set B comes with an extra of +5 EUR)
(-) the only possibility to take over the SKU to the cart would be to manually type the SKU in the cart variant Field. As a result both SKUs (the SKU of the parent + the cart variant text) would show up in the cart overview (which is confusing)

2) Solution: Generic Child Variant.
First you create the child. open the "shovel" product, go to product details and create the child product. For the child product, which I named "shovel with extra handle", I put the separate SKU and the separate price (the full price, not an additional price like in the shopping cart variant).
Then you go to custom fields, create a generic child variant (published: yes, cart attribute: yes, admin only: no, list: no, hidden: no).
Go to your parent product and add the generic child variant field. Save.

Result:
(+) Options are shown in drop down
(+) page and price refreshes when different options are chosen
(+) SKU of the variant and separate price is taken to shopping cart
(-) almost perfect, however, when changing the options in the dropdown to "shovel with spare handle" it shows the product details of the child with the title "shovel with spare handle" (as the values in the drop down menu for generic child variants is the product title) which I didn't want. I wanted just "shovel", so the name of the parent to be displayed for both, child and parent.

The solution to this is basically a hack in the product details view, which displays a custom string (which will be "shovel") for all child products. I found this nice explanation how to do it (thanks mowgs!): https://forum.virtuemart.net/index.php?topic=90833.170;wap2

As said, I'm a complete beginner and I managed to do it. Fo me it does what it should, and i am SOOOO HAPPY that I finally found a solution. Maybe it helps you as well.

Best

gothamcity

#241
Hi mowgs,
thank you so much, your post with the overwrite really helped a lot!!! I have been searching for ages to find a solution to set up generic child variants to work this way.
I think it would help a lot of users to take this further and implement basically a shell parent - I am quite sure it in principle works with your overwrite. I created a parent with child products, did not publish the parent and assigned the category to one child. However, in the "category view" now the child title is being displayed (of course).
I see the default php of the category has
<h2><?php echo JHTML::link($product->link, $product->product_name); ?></h2>
in it. I have to admit I am a complete beginner (especially php), it would be very nice if you could give me a hint how to adapt your code to also work for the category view. I already tried several times, but I could not find out how to set the second parameter of the link to display the custom title.

Best

spyderwebdesign

I believe I have the Generic Cart Variants working. Are there any bugs I should know about? Here is the site I am currently working on. Planning to setup paypal sandbox tomorrow so I can do test ordering to see if stock gets reduced. If that works, then I just have a ton of formatting changes to make.

http://www.likdancewear.com/component/virtuemart/4-1-2-heel.html

bunglehaze

Quote from: gothamcity on April 25, 2012, 23:32:12 PM
Hi all,
I'm a complete Newby and like many of yours I tried for days to find out a solution to deal with the product variants in VM2 (2.0.6 exactly). I read tons of posts/threads read people attacking Milbo who is doing a great job, in my opinion.
As you see it's my firt thread, but as I finally found a solution for my shop; I loved to give somethin back to the community.

So, what was my issue?
My shop has products with different scopes of supply (e.g. you have the basic product, a shovel (set A), another option with the shovel and a spare handle (set B)).
What I wanted was
a) a drop-down in the add-to-cart area that refreshes the price depending on the option chosen
b) as my sets have different SKUs I needed the SKU to be taken into the shopping cart (and the invoice later on), as otherwise order processing would be difficult

1) Solution A: a cart variant.
(+) easy to set up
(+) price refreshes
(-) only works with extra price for the option (so, e.g. Set B comes with an extra of +5 EUR)
(-) the only possibility to take over the SKU to the cart would be to manually type the SKU in the cart variant Field. As a result both SKUs (the SKU of the parent + the cart variant text) would show up in the cart overview (which is confusing)

2) Solution: Generic Child Variant.
First you create the child. open the "shovel" product, go to product details and create the child product. For the child product, which I named "shovel with extra handle", I put the separate SKU and the separate price (the full price, not an additional price like in the shopping cart variant).
Then you go to custom fields, create a generic child variant (published: yes, cart attribute: yes, admin only: no, list: no, hidden: no).
Go to your parent product and add the generic child variant field. Save.

Result:
(+) Options are shown in drop down
(+) page and price refreshes when different options are chosen
(+) SKU of the variant and separate price is taken to shopping cart
(-) almost perfect, however, when changing the options in the dropdown to "shovel with spare handle" it shows the product details of the child with the title "shovel with spare handle" (as the values in the drop down menu for generic child variants is the product title) which I didn't want. I wanted just "shovel", so the name of the parent to be displayed for both, child and parent.

The solution to this is basically a hack in the product details view, which displays a custom string (which will be "shovel") for all child products. I found this nice explanation how to do it (thanks mowgs!): https://forum.virtuemart.net/index.php?topic=90833.170;wap2

As said, I'm a complete beginner and I managed to do it. Fo me it does what it should, and i am SOOOO HAPPY that I finally found a solution. Maybe it helps you as well.

Best


I dont think any of us are attacking Milbo actually, the devs have put a lot of work into remaking VM into a new version which is commendable, BUT when massive sections of the software have had catastrophic failures and errors from the first stable release it is expected that those of us who adopted early, helped find bugs etc are going to feel let down at certain aspects. In this case the old version of VM had a pretty basic functionality that most ecommerce sites use, the first iteration of VM2 needed things altering, but then used it just fine and then all of a sudden in the third or 4th stable release 'bugfix' the functionality disappears.

Not only is this frustrating, but in a lot of cases it is a site breaker. In order to make my site work again I have to totally redevelop huge sections, then following on from the way these simple bugfixes have massively altered functionality (remember we are supposed to be stable) there is no guarantee that the original, preferred function is made to work again and the version I spent so much time switching to breaks.

No doubt there is a way to make the cart variant work, but it is not the way we have already setup based on VM2 and rebuilding an existing site can and does take a while.

mowgs

Quote from: gothamcity on April 25, 2012, 23:32:12 PM
Hi all,
I'm a complete Newby and like many of yours I tried for days to find out a solution to deal with the product variants in VM2 (2.0.6 exactly). I read tons of posts/threads read people attacking Milbo who is doing a great job, in my opinion.
As you see it's my firt thread, but as I finally found a solution for my shop; I loved to give somethin back to the community.

So, what was my issue?
My shop has products with different scopes of supply (e.g. you have the basic product, a shovel (set A), another option with the shovel and a spare handle (set B)).
What I wanted was
a) a drop-down in the add-to-cart area that refreshes the price depending on the option chosen
b) as my sets have different SKUs I needed the SKU to be taken into the shopping cart (and the invoice later on), as otherwise order processing would be difficult

1) Solution A: a cart variant.
(+) easy to set up
(+) price refreshes
(-) only works with extra price for the option (so, e.g. Set B comes with an extra of +5 EUR)
(-) the only possibility to take over the SKU to the cart would be to manually type the SKU in the cart variant Field. As a result both SKUs (the SKU of the parent + the cart variant text) would show up in the cart overview (which is confusing)

2) Solution: Generic Child Variant.
First you create the child. open the "shovel" product, go to product details and create the child product. For the child product, which I named "shovel with extra handle", I put the separate SKU and the separate price (the full price, not an additional price like in the shopping cart variant).
Then you go to custom fields, create a generic child variant (published: yes, cart attribute: yes, admin only: no, list: no, hidden: no).
Go to your parent product and add the generic child variant field. Save.

Result:
(+) Options are shown in drop down
(+) page and price refreshes when different options are chosen
(+) SKU of the variant and separate price is taken to shopping cart
(-) almost perfect, however, when changing the options in the dropdown to "shovel with spare handle" it shows the product details of the child with the title "shovel with spare handle" (as the values in the drop down menu for generic child variants is the product title) which I didn't want. I wanted just "shovel", so the name of the parent to be displayed for both, child and parent.

The solution to this is basically a hack in the product details view, which displays a custom string (which will be "shovel") for all child products. I found this nice explanation how to do it (thanks mowgs!): https://forum.virtuemart.net/index.php?topic=90833.170;wap2

As said, I'm a complete beginner and I managed to do it. Fo me it does what it should, and i am SOOOO HAPPY that I finally found a solution. Maybe it helps you as well.

Best

Thanks GothamCity - It was all corymp's work, I just linked to it???

Things are starting to get working now for some people, just the stockable bit thats causing problems!

Bruce Morgan

Spyderwebdesign, I like the look of your test site.  I like the help menu and may use it as a model for my own site. 

Bunglehaze, I agree, with you.  Atrributes/custom fields is the "achilles heel" of the new VM.  It is over the top complex layered with numerous bugs so that I have been stymied in my attemopts to really evaluate this feature.  My conslusion so far is that it is a complete dud and should be preority one for re-working by the development team.  It is the largest obstacle i can see in transitioning my live site to the new platform.  Ironically, I have had the best luck using the "dropbox" plugin written by Banquest Table Pros.

I appreciate the work you guys are doing.  I hope it will help lead me to a solution down the road.

spyderwebdesign

Quote from: Bruce Morgan on April 26, 2012, 17:16:20 PM
Spyderwebdesign, I like the look of your test site.  I like the help menu and may use it as a model for my own site. 

Thank you. Feel free to use anything you like from my site and feel free to ask any questions.

bambarbia

#247
Good evening to everybody.

I also met this annoying 'feature' in VM 2 today, when I was needed to create parent+several children products, where each of relatives has different custom fields.
So when I found out that after going to child product from the parent's generic child list, there were no more other 'families'  :-\

VM crew making their best for sure. Let's don't blame them ;)

I made core hack before they will add this functions in future. My VM version is 2.0.4.

Steps (some comments in code):
1. Changes in administrator\components\com_virtuemart\models\customfields.php

// line 571 from:
public function getProductCustomsFieldCart($product) {
// to
public function getProductCustomsFieldCart($product, $relatives = false) {

// line 673 from:
$group->display .= $this->displayType($productCustom->custom_value,$group->field_type,0,'',$row,1) ;
// to:
if($relatives) return $this->displayType($productCustom->custom_value,$group->field_type,0,'',$row,1);

// added after line 755:
return count($uncatChildren) > 1 ? $uncatChildren : '';


2. Changes in administrator\components\com_virtuemart\models\product.php

// right after line 661 added:
$product->relatives = $customfields->getProductCustomsFieldCart($product, true);

// line 1534 query fix - from:
$q = 'SELECT * FROM `#__virtuemart_products` as p

// to (for me it's enough to have only this):
$q = 'SELECT virtuemart_product_id, product_name FROM `#__virtuemart_products` as p

// and the last one for core - after line 1560 (here we adding to our array images and links of products):
$mediaModel = VmModel::getModel('Media'); // *** OPTIONAL ***
$i = 0;
foreach($res as $v){
$res[$i]["images"] = $mediaModel->getFiles(true, false, $v["virtuemart_product_id"]); // *** OPTIONAL ***
$res[$i]["link"] =  'index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id='.JFactory::getSession()->get('vmlastvisitedcategoryid', 0, 'vm').'&virtuemart_product_id='.$v["virtuemart_product_id"];
$i++;
}


*** OPTIONAL *** - only if you need pictures\thumbs of the products. Remove for more perfomance.

Now we can use $product->relatives array in our views. You can see contents of it by using php print_r function.
For example add this code somewhere in views\productdetails\tmpl\default_addtocart.php :
print_r($this->product->relatives);
It'll be easy now to make any kind of buttons\dropdown lists etc.

That's all, I guess, hope you'll find it helpful ;)

Bruce Morgan

Not really sure what you have done here.  Do you have a live site where we can see what you have done?  If not a few screen shots would be great.

bambarbia

Sorry, can't give live example site right now, but can describe it more detailed.

This changes will give you ability to switch between parent and its child product(s) even if child product(s) has\have their own custom fields which differs from parent fields (i.e. "Overwrite plugin values of the parent" in product's tab "Custom Fields" must be checked).

Attached some screenshots, this is after working a bit with $this->product->relatives Array in default_addtocart.php.


[attachment cleanup by admin]

Bruce Morgan

Still has me a little confused.  The two images look quite similar and if the frst one is a child should'nt it be either metal plastic or wood?  It seems that you could click the add to cart button and the material type would not be specified.  Are satisfied with the modification you have made?

bambarbia

They are similar because of no page styling. I thought it's enough understandable :-\

Each link leading to the product flypage, as if you were selecting from usual dropdown list, i.e. ladder little image above "Add to cart" (it's image link, because I write code in default_addtocart.php for rendering images of products, if they exist, instead of just text links), and other 3 links (Wooden, Plastic, Metal) to the child products (they don't have images, so only text links).

Yes, I'm quite satisfied :)

leFlea

Great things happening on this thread!

@bambarbia, with your hack can we do this?

ex. I have one t-shirt type, offered in different sizes for each color. I wan't to track inventory for each color and size but I only want them in a single product page (meaning one entry in category view). Each product attribute must be a drop down menu.

Product: Round Neck T-Shirt
Color Variants:
1. White, available in size: XXL, XS, S, M, L, XL, XXL
2. Black, available in size: XXS, XS, S, M, L, XL, XXL
3. Red, available in size: XS, S, M, L, XL
4. Blue, available in size: XS, S, M, L, XL
5. Purple, available in size: S, M, L
6. Green, available in size: L

bambarbia

#253
Yes, theflea, you can do this with this hack ;) It won't be AJAX (I think it's easy to add, but not required in my current project, so I skipped this for now), like in default VM1 theme, but it will be possible to switch between parent and its children (children will be uncategorized, so category view will show only parent).

P.S. If you want to track inventory separately for color and inventory for 1 product (product or child doesn't matter), I mean, for example:
T-Shirt - White, available in size: XXL(3 in stock), XS(6 in stock), S(don't have now, give us email to inform when we'll) and so on. So we don't show how many white T-Shirts we have, because it's not important, but their sizes instead.
It's more complex and not possible to do this in 1 product without adding this functionality to core  (as I know, maybe I just missed something) or use some trick with custom fields. Btw, using Custom Fields Plugin - stockable variants is not a solution in this case, a little bit "dirty" game for me  ;)

spyderwebdesign

#254
Quote from: corymp on March 20, 2012, 11:06:24 AM
/templates/yourtemplate/html/com_virtuemart/category/default.php

I do not have the folder com_virtuemart/ in /templates/yourtemplate/html/ Did you custom make that? I am scared that if I make changes in the category/default.php that I will lose them when vm updates.

My goal is to remove the Parent item from the first item in the drop down list and replace with "Please choose a size".