VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: emedina on January 24, 2017, 13:10:31 PM

Title: One customfield, several products in vm3
Post by: emedina on January 24, 2017, 13:10:31 PM
Hi everybody.

A small introduction. Imagine you have a t-shirt store. You need Size customfield, maybe color one. In your store you have 1000 products, so in your virtuemart_product_customfields table you have 6000 entries. That's a lot.

In virtuemart 2 I found a trick. I only asigned size and colour in one product. Then copy the customfields template html output and paste in the whole template. In helpers/cart.php i commented:
// $product -> customfieldsCart = empty($tmpProduct -> customfieldsCart)? array(): $tmpProduct -> customfieldsCart;
With this little hack, all products in cart had the size and colour customfields.

Now in vm3 is more dificult. In helpers/cart.php the function "add" check customfields with this line:
$product->customfields = $customFieldsModel->getCustomEmbeddedProductCustomFields($product->allIds,0,1);

Ok, i've developed a plugin that extends virtuemartCart and links a custom vmprices.js in the frontend. When i debug the cart, the products have "fake" customfields (ok, that's good), but are not showing in the cart, neither in orders because product customfields are checked more times with the function getCustomEmbeddedProductCustomFields.


Is there anyway to make this work again without hacking the core? Maybe a pluggin that modify the product in the cart and in the order?

Thanks a lot.
Title: Re: One customfield, several products in vm3
Post by: Milbo on January 26, 2017, 00:12:20 AM
Product pattern? https://docs.virtuemart.net/manual/general-concepts/186-derived-products-product-pattern-child-products.html
Title: Re: One customfield, several products in vm3
Post by: emedina on January 26, 2017, 17:39:22 PM
That is a very good solution, but i've customers who are accustomed to create products without specifing product's parent.
I'm wondering what would happen if i create a product with all the customfields and then override all products in template like this $this->product->product_parent_id=$the_fake_one.

I think the template isn't the best place to do this. Maybe in a plugin, but, is there any list with all the plugins triggers?

P.S. GREAT job team!!
Title: Re: One customfield, several products in vm3
Post by: Milbo on January 27, 2017, 08:58:29 AM
I do not understand, why you cannot use the pattern, you should play a bit with it.