1: | <?php
2: | namespace Opencart\Catalog\Model\Extension\Opencart\Shipping;
3: | /**
4: | * Class Weight
5: | *
6: | * @package Opencart\Catalog\Model\Extension\Opencart\Shipping
7: | */
8: | class Weight extends \Opencart\System\Engine\Model {
9: | /**
10: | * Get Quote
11: | *
12: | * @param array<string, mixed> $address
13: | *
14: | * @return array<string, mixed>
15: | */
16: | public function getQuote(array $address): array {
17: | $this->load->language('extension/opencart/shipping/weight');
18: |
19: | $quote_data = [];
20: |
21: | $this->load->model('localisation/geo_zone');
22: |
23: | $results = $this->model_localisation_geo_zone->getGeoZones();
24: |
25: | $weight = $this->cart->getWeight();
26: |
27: | foreach ($results as $result) {
28: | if ($this->config->get('shipping_weight_' . $result['geo_zone_id'] . '_status')) {
29: | $results = $this->model_localisation_geo_zone->getGeoZone($result['geo_zone_id'], $address['country_id'], $address['zone_id']);
30: |
31: | if ($results) {
32: | $status = true;
33: | } else {
34: | $status = false;
35: | }
36: | } else {
37: | $status = false;
38: | }
39: |
40: | if ($status) {
41: | $cost = '';
42: |
43: | $rates = explode(',', $this->config->get('shipping_weight_' . $result['geo_zone_id'] . '_rate'));
44: |
45: | foreach ($rates as $rate) {
46: | $data = explode(':', $rate);
47: |
48: | if ($data[0] >= $weight) {
49: | if (isset($data[1])) {
50: | $cost = $data[1];
51: | }
52: | break;
53: | }
54: | }
55: |
56: | if ((string)$cost != '') {
57: | $quote_data['weight_' . $result['geo_zone_id']] = [
58: | 'code' => 'weight.weight_' . $result['geo_zone_id'],
59: | 'name' => $result['name'] . ' (' . $this->language->get('text_weight') . ' ' . $this->weight->format($weight, $this->config->get('config_weight_class_id')) . ')',
60: | 'cost' => $cost,
61: | 'tax_class_id' => $this->config->get('shipping_weight_tax_class_id'),
62: | 'text' => $this->currency->format($this->tax->calculate((float)$cost, $this->config->get('shipping_weight_tax_class_id'), $this->config->get('config_tax')), $this->session->data['currency'])
63: | ];
64: | }
65: | }
66: | }
67: |
68: | $method_data = [];
69: |
70: | if ($quote_data) {
71: | $method_data = [
72: | 'code' => 'weight',
73: | 'name' => $this->language->get('heading_title'),
74: | 'quote' => $quote_data,
75: | 'sort_order' => $this->config->get('shipping_weight_sort_order'),
76: | 'error' => false
77: | ];
78: | }
79: |
80: | return $method_data;
81: | }
82: | }
83: |

OpenCart API API documentation generated by ApiGen dev-master