public function WeightQuote::getQuotes in Ubercart 8.4
Retrieves shipping quotes for this method.
Parameters
\Drupal\uc_order\OrderInterface $order: The order to retrieve the quotes for.
Return value
array An array of shipping quotes.
Overrides ShippingQuotePluginInterface::getQuotes
File
- shipping/
uc_quote/ src/ Plugin/ Ubercart/ ShippingQuote/ WeightQuote.php, line 92
Class
- WeightQuote
- Assigns a shipping rate to products based on weight.
Namespace
Drupal\uc_quote\Plugin\Ubercart\ShippingQuoteCode
public function getQuotes(OrderInterface $order) {
$rate = $this->configuration['base_rate'];
$field = $this->configuration['field'];
foreach ($order->products as $product) {
if (isset($product->nid->entity->{$field}->value)) {
$product_rate = $product->nid->entity->{$field}->value * $product->qty->value;
}
else {
$product_rate = $this->configuration['product_rate'] * $product->qty->value;
}
$rate += $product_rate * $product->weight->value * uc_weight_conversion($product->weight->units);
}
return [
$rate,
];
}