News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Child Product Weight to Calculate Shipping

Started by qb-virtue, June 23, 2015, 22:51:31 PM

Previous topic - Next topic

qb-virtue

Hello,
Working on a Joomla 3 site with VM 3 and need to have a way to set up a product with multiple children or variants that changes the price and weight, which will effect the shipping.
For example:

Product A comes in 8 different lengths. Each length is a different weight and price. Shipping is based on the weight.

What is the best way to set this up? Multi-variant, Child Products...?
Any help would be greatly appreciated, I have searched the forum and Google for the last 2 hours trying to find an answer and I'm completely stumped.

AH

Regards
A

Joomla 4.4.5
php 8.1

qb-virtue


AH

You could try this

http://forum.virtuemart.net/index.php?topic=127362.0

we sell in lengths and the length modifier mutliplies the weight as well if required

So for your example
The configuration would look like this:
Length:

1m,2m@*2,3m@*3,4m@*4,5@*5,6@*6,7@*7,8@*8


You just set the price on the product and add the dropbox, plugin customfield to every product you want to sell like this and that is pretty much it

When the price for the product changes the multiplier works

Regards
A

Joomla 4.4.5
php 8.1

qb-virtue

Unfortunately there is no set multiplier that would work for my weight/pricing.

For instance:
Child 1 - 12lb/$20
Child 2 - 15lb/$20
Child 3 - 23lb/$25
Child 4 - 31lb/$33
Child 5 - 35lb/$38
Child 6 - 38lb/$42
Child 7 - 46lb/$50

And the shipping cost has to be calculated based on the weight. I don't think that would work with DropBox, do you?

AH

#5
Unfortunately the plugin does not currently support the separate weight setting based on what you show in the configuration

I had considered doing that but got lazy as I realised I only needed weights that directly followed my mulitplier scheme

However if you can edit a bit of php I have posted the possible solution below

e.g.
Consider the starting price is $20 - you don't need a pricemodifier for the 12 and 15lb - but we want a weight modifier for every entry

12lb@@12,15lb@@15,23lb@+5@23,31lb@+13@31,35lb@+18@35,38lb@+22@38@46lb@+30@46

The first @ is the break for the price, the second @ is for the weight

i.e.   dropname@droppricemodifier@dropweightvalue

Using the + modifier allows a change in the basic price to affect a change in all other prices - however that change is not a proportional change

If you used a *0.xx then you may be able to keep the proportional prices the same even with an increase to the basic price


drop.php needs a change and when configuring a second value needs to be considered (see above for the config)


You can try using the code below (NOTE THAT I HAVE NOT TESTED THIS SO PLEASE DO ON A TEST SITE!)

Old function


public function plgVmPrepareCartProduct(&$product, &$customfield,$selected,&$modificatorSum = 0){
if ($customfield->custom_element !==$this->_name) return ;
//$product->product_name = 'Ice Saw';
//vmdebug('plgVmPrepareCartProduct we can modify the product here');
if (!empty ($selected['custom_drop'])) {
$options = explode(',', $customfield->custom_drop);
foreach ($options as $valuesWithPrice) {
$valueWithPrice = explode('@', $valuesWithPrice);
if ($selected['custom_drop'] == $valueWithPrice[0]) {
if (isset ($valueWithPrice[1])) {
$op = $valueWithPrice[1][0];
$qdropmodprice = $product->allPrices[$product->selectedPrice]["product_price"];
$qnewmodprice = 0;
switch ($op) {
case "+":
$modificatorSum += (float)substr($valueWithPrice[1], 1);
break;
case "=":
$qdropfixed = (float)substr($valueWithPrice[1], 1);
if ($qdropfixed > 0) {
$qnewmodprice = $qdropfixed - $qdropmodprice;
}
$modificatorSum += $qnewmodprice;
break;
case "-":
$modificatorSum -= (float)substr($valueWithPrice[1], 1);
break;
case "*":
                                // Use the price for this customer and multiply it by the variant -1 as this then gets added to the price for a single product
                                // You do not need @*1 but need @*2
                                    $qdropmultiplier = substr($valueWithPrice[1], 1);
                                    if ($qdropmultiplier > 0) {
                                        $qnewmodprice = $qdropmodprice * ($qdropmultiplier - 1);
                                    //Determine if the product weight needs multiplying
                                    if ($customfield->custom_drop_weight){
                                        // adjust the weight of the cart item for dropdown selection
                                        $qmodweight = $product->product_weight * $qdropmultiplier;
                                        $product->product_weight = "$qmodweight";
                                    }
                                }
$modificatorSum += $qnewmodprice;
break;
default:
$modificatorSum += (float)$valueWithPrice[1];
}
}
                    // modify the SKU to add the suffix
                    $sku_modifier = "";
                    $sku_modifier = $valueWithPrice[2];
                    if ($sku_modifier !="") {
                        $product->product_sku = $product->product_sku . "-" . $sku_modifier;

                    }
                    //end sku

return;
}
}
}
}



New function - this might work for you or at least if you can code you can play with it some more



public function plgVmPrepareCartProduct(&$product, &$customfield,$selected,&$modificatorSum = 0){
if ($customfield->custom_element !==$this->_name) return ;
//$product->product_name = 'Ice Saw';
//vmdebug('plgVmPrepareCartProduct we can modify the product here');
if (!empty ($selected['custom_drop'])) {
$options = explode(',', $customfield->custom_drop);
foreach ($options as $valuesWithPrice) {
$valueWithPrice = explode('@', $valuesWithPrice);
if ($selected['custom_drop'] == $valueWithPrice[0]) {
if (isset ($valueWithPrice[1])) {
$op = $valueWithPrice[1][0];
$qdropmodprice = $product->allPrices[$product->selectedPrice]["product_price"];
$qnewmodprice = 0;
switch ($op) {
case "+":
$modificatorSum += (float)substr($valueWithPrice[1], 1);
break;
case "=":
$qdropfixed = (float)substr($valueWithPrice[1], 1);
if ($qdropfixed > 0) {
$qnewmodprice = $qdropfixed - $qdropmodprice;
}
$modificatorSum += $qnewmodprice;
break;
case "-":
$modificatorSum -= (float)substr($valueWithPrice[1], 1);
break;
case "*":
                                // Use the price for this customer and multiply it by the variant -1 as this then gets added to the price for a single product
                                // You do not need @*1 but need @*2
                                    $qdropmultiplier = substr($valueWithPrice[1], 1);
                                    if ($qdropmultiplier > 0) {
                                        $qnewmodprice = $qdropmodprice * ($qdropmultiplier - 1);
//                                    //Determine if the product weight needs multiplying
//                                    if ($customfield->custom_drop_weight){
//                                        // adjust the weight of the cart item for dropdown selection
//                                        $qmodweight = $product->product_weight * $qdropmultiplier;
//                                        $product->product_weight = "$qmodweight";
//                                    }
                                }
$modificatorSum += $qnewmodprice;
break;
default:
$modificatorSum += (float)$valueWithPrice[1];
}
}

                    if ($customfield->custom_drop_weight) {
                        $weight_modifier = "";
                        $weight_modifier = $valueWithPrice[2];
                        if ($weight_modifier != "") {
                            // adjust the weight of the cart item for dropdown selection
                            $product->product_weight = "$weight_modifier";
                        }
                    }   
//                    // modify the SKU to add the suffix
//                    $sku_modifier = "";
//                    $sku_modifier = $valueWithPrice[2];
//                    if ($sku_modifier !="") {
//                        $product->product_sku = $product->product_sku . "-" . $sku_modifier;
//
//                    }
//                    //end sku

return;
}
}
}
}




If you don't put a weight modifier for a drop option, the weight will be the same as the basic product weight

Note that this is not in the released version


If you use two @@'s for a drop option in the released version the plugin will modify your sku by appending the second @ property to the sku  e.g. sku1-31, sku1-13
( a feature I also really needed to allow sales of drop items to update stock items in a third party accounting system -note the stock in VM is not affected)
Regards
A

Joomla 4.4.5
php 8.1

Adwans

Its June 2016, has anybody implemented this solution yet?
qb-virtue, did you?

if ($customfield->custom_drop_weight) {
                        $weight_modifier = "";
                        $weight_modifier = $valueWithPrice[2];
                        if ($weight_modifier != "") {
                            // adjust the weight of the cart item for dropdown selection
                            $product->product_weight = "$weight_modifier";

GJC Web Design

If AH hasn't I think it is easy to guess why..

All time is given voluntarily here..  AH answers the guy with a very full response and what does he receive in return?

Nix, nada, zilch,

no feedback, no thank you.. not even a reply.. sadly this is way too common..
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

WHy
$product->product_weight = "$weight_modifier";
and not
$product->product_weight = $weight_modifier;
?
Quote is not needed.

@GJC Web Design : not only user but some member have same attitude, i wait for reply for some bugs and because this i don't send not other bugs i know. I have found 3 or 4 new bugs in vm 3.0.16 this week, but only reported one because i have no answer or he get ignored.

AH

#9
@studio 42

Good catch - this was not tested at all - I have no idea why I enclosed it in ""
Regards
A

Joomla 4.4.5
php 8.1

lindapowers

#10
Dont understand this post, all can be achieved with the core generic child variant and multivariants.

Each variant there has is own weight so cart will take the value of the variant and you can create as many as you want.

Not elegant and simple to manage but it works.

Another thing is if you wanted string custom fields to change weight for shipping, AH solution is nice for that.

Actually is quite nonsense that we need to use childs and multivariants for measurement variants but VM didnt add option to modify weight for simple string custom fields and managing each variant as a product is not very user friendly.

AH

LP

You have answered your own question regarding the point of this post.

Quotecore generic child variant and multivariants.
QuoteNot elegant and simple to manage but it works.

In addition to allowing very simple management of Cart variant attributes.  The free plugin "VM3 Product Cart Variant Custom Field / Attribute Plugin"  can easily be modified to achieve the requirement for this user.

As long as you do not require VM to manage your stock control, IMHO the core child variant/multivariant is overly complex for some situations.


Regards
A

Joomla 4.4.5
php 8.1

lindapowers

#12
The basic issue is that string variants need weight field cause many users need shipping based on weight as these guys and  having to create childs or multivariants for colours or measurement units is not ideal.

Yes I agree with you in that childs and multivariants are too complex in some situations, in many ill say. They make sense when variants are products or subproducts with unique photos, descriptions etc but loading "colour blue" as a product or "31 lb" .....

The confusion comes with the title of the post, childs and multivariants allow weight change for shipping, strings don't and that is what he will want to use cause the example he provides are strings.

What VM calls Multivariants is really a multiple childs concept.
The multivariant is the string custom field cause those are variants and checking the VM demo in the backend I doubt someone uses multivariants creating 1 product for each variant ending up with 3 million products in the backend.


AH

QuoteThe confusion comes with the title of the post, childs and multivariants allow weight change for shipping, strings don't and that is what he will want to use cause the example he provides are strings.

What I posted above - was a solution to modify this plugin to achieve a string PLUS a weight override
Regards
A

Joomla 4.4.5
php 8.1