public function calculate_shipping($package)
 {
     $package = WbsPackage::fromWcPackage($package);
     if (!$this->weight->includes($package->getWeight()) || !$this->subtotal->includes($package->getPrice($this->subtotalWithTax))) {
         return;
     }
     $defaultRate = new WbsBucketRate('___wbs_base_pseudo_class', $this->fee, $this->weightRate);
     /** @var WbsItemBucket[] $buckets */
     $buckets = array();
     foreach ($package->getLines() as $line) {
         $product = $line->getProduct();
         $class = $product->get_shipping_class();
         $rate = $this->shippingClassRates->findById($class);
         if ($rate == null) {
             $rate = $defaultRate;
         }
         $class = $rate->getId();
         if (!isset($buckets[$class])) {
             $buckets[$class] = new WbsItemBucket(0, $rate);
         }
         $buckets[$class]->add($line->getWeight());
     }
     $defaultClass = $defaultRate->getId();
     if (!isset($buckets[$defaultClass])) {
         $buckets[$defaultClass] = new WbsItemBucket(0, $defaultRate);
     }
     $price = 0;
     foreach ($buckets as $bucket) {
         $price += $bucket->calculate();
     }
     $price = $this->priceClamp->clamp($price);
     $this->add_rate(array('id' => $this->id, 'label' => $this->title, 'cost' => $price, 'taxes' => '', 'calc_tax' => 'per_order'));
 }
 private function shippingClassRateRow($inputNamePrefix, $rateId, WbsBucketRate $rate = null, $class = null)
 {
     return '
         <tr class="flat_rate ' . esc_html($class) . '">
             <th class="check-column">
                 <input type="checkbox" name="select" />
             </th>
             <td class="flat_rate_class">
                 ' . $this->shippingClassSelect("{$inputNamePrefix}[{$rateId}][class]", $rate ? $rate->getId() : null) . '
             </td>
             <td>' . $this->decimalInput(array('value' => $rate ? $rate->getFlatRate() : null, 'name' => "{$inputNamePrefix}[{$rateId}][fee]")) . '
             </td>
             <td>' . $this->weightRate("{$inputNamePrefix}[{$rateId}][weight_rate]", $rate ? $rate->getProgressiveRate()->toArray() : null, false) . '
             </td>
         </tr>
     ';
 }
Ejemplo n.º 3
0
 public function add(WbsBucketRate $rate)
 {
     $this->rates[$rate->getId()] = $rate;
 }
Ejemplo n.º 4
0
 public function calculate()
 {
     return $this->rate->rate($this->quantity);
 }