Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option weights ignored #4

Open
katalysis opened this issue Jan 25, 2018 · 4 comments
Open

Option weights ignored #4

katalysis opened this issue Jan 25, 2018 · 4 comments

Comments

@katalysis
Copy link

I have the table rates extension working well on a site to deliver different rates per country based on weight.

However this stops working for product options.

For example I have a product option here: https://www.laserphysics.co.uk/store/clinic-products/consumables/laser-ipl-gel for a '4 x 5 L cubitainer'

screenshot-www laserphysics co uk-2018-01-25-11-37-00-345

This is set up as an option with a 20.2kg weight.

The table rate for shipping this to Sweden is £144 but shipping is set at checkout at £65 which is the rate for shipping anything less than 0.5kg (the weight for the base product is set at 0).

SE * *   65
SE * * 0.5 67
SE * * 1 72
SE * * 2 83
SE * * 3 104
SE * * 5 112
SE * * 7 121
SE * * 10 132
SE * * 15 144

screenshot-www laserphysics co uk-2018-01-25-11-41-56-875

It seems that option weights are ignored in the shipping calculation?

@Jozzeh
Copy link
Collaborator

Jozzeh commented Jan 25, 2018

I think at the time of creating the package, there were no option weights... (I could be wrong)
I'll have a look as soon as possible.

The code in TablerateShippingMethod.php uses the following code to calculate the weight :

    $totalWeight = 0;
    foreach ($shippableItems as $item) {
        $product = StoreProduct::getByID($item['product']['pID']);
        if ($product->isShippable()) {
            $totalProductWeight = $item['product']['qty'] * $product->getWeight();
            $totalWeight = $totalWeight + $totalProductWeight;
        }
    }
    return $totalWeight;

So it's probably the product->getWeight function that looks at the standard weight of a product and not the selected option. Perhaps @Mesuva can correct me if I'm wrong ?

@Jozzeh
Copy link
Collaborator

Jozzeh commented Jan 25, 2018

I've had a look at the $product->getWeight() function and it seems to take into account the variation weight ...

public function getWeight()
{
    $weight = $this->pWeight;
    if ($this->hasVariations() && $variation = $this->getVariation()) {
        $varWeight = $variation->getVariationWeight();
        if ($varWeight) {
            return $varWeight;
        }
    }
    return $weight;
}

I'll try to reproduce your error and debug it as soon as possible (but i'm quite busy atm).

@katalysis
Copy link
Author

I think the issue here might be that getTotalWeight($shippableItems) locates the product using $product = StoreProduct::getByID($item['product']['pID']); at this point I think the variation information is lost and the weight of only the main product is returned.

@katalysis
Copy link
Author

Got it, these lines need adding at line 267

        if ($item['product']['variation']) {
            $product->setVariation($item['product']['variation']);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants