\brief Generate shipping options to pass to 'answerShippingQuery'.
@param array $shipping_options The various shipping options represented like PHP data types.
@return string A JSON string representation of the shipping options.
437105
private function generateShippingOptions(array $shipping_options) {
      $response = [];
      $option_index = 1;

      foreach ($shipping_options as $option => $prices) {
        array_push($response, ['id' => strval($option_index), 'title' => $option, 'prices' => []]);

        // Register prices for the specific shipping option
        foreach ($prices as $service => $price) {
          if ($price < 0) {
            throw new Exception('Invalid negative price passed to "answerShippingQuery"');
          }

          $formatted_price = intval($price * 100);

          // Selects the most recent shipping option pushed into the array.
          array_push($response[$option_index - 1]['prices'], [
            'label' => $service, 'amount' => $formatted_price
          ]);
        }

        $option_index++;
      }

      return json_encode($response);
    }
1322756
protected function getPrestaShopOptions(array $options)
    {
        $result = array(
            'query' => array(),
            'id' => 'id',
            'name' => 'name',
        );

        foreach ($options as $value => $label) {
            $result['query'][] = array(
                'id' => $value,
                'name' => $label,
            );
        }

        return $result;
    }
52618
def build_checkout_params(self, **kwargs):
        
        params = kwargs or {}
        if self.sender:
            params['senderName'] = self.sender.get('name')
            params['senderAreaCode'] = self.sender.get('area_code')
            params['senderPhone'] = self.sender.get('phone')
            params['senderEmail'] = is_valid_email(self.sender.get('email'))
            params['senderCPF'] = is_valid_cpf(self.sender.get('cpf'))
            params['senderCNPJ'] = is_valid_cnpj(self.sender.get('cnpj'))
            params['senderBornDate'] = self.sender.get('born_date')
            params['senderHash'] = self.sender.get('hash')

        if self.config.USE_SHIPPING:
            if self.shipping:
                params['shippingType'] = self.shipping.get('type')
                params['shippingAddressStreet'] = self.shipping.get('street')
                params['shippingAddressNumber'] = self.shipping.get('number')
                params['shippingAddressComplement'] = self.shipping.get(
                    'complement')
                params['shippingAddressDistrict'] = self.shipping.get(
                    'district')
                params['shippingAddressPostalCode'] = self.shipping.get(
                    'postal_code')
                params['shippingAddressCity'] = self.shipping.get('city')
                params['shippingAddressState'] = self.shipping.get('state')
                params['shippingAddressCountry'] = self.shipping.get('country',
                                                                     'BRA')
                if self.shipping.get('cost'):
                    params['shippingCost'] = self.shipping.get('cost')
        else:
            params['shippingAddressRequired'] = 'false'

        if self.extra_amount:
            params['extraAmount'] = self.extra_amount

        params['reference'] = self.reference
        params['receiverEmail'] = self.data['email']

        if self.redirect_url:
            params['redirectURL'] = self.redirect_url

        if self.notification_url:
            params['notificationURL'] = self.notification_url

        if self.abandon_url:
            params['abandonURL'] = self.abandon_url

        for i, item in enumerate(self.items, 1):
            params['itemId%s' % i] = item.get('id')
            params['itemDescription%s' % i] = item.get('description')
            params['itemAmount%s' % i] = item.get('amount')
            params['itemQuantity%s' % i] = item.get('quantity')
            params['itemWeight%s' % i] = item.get('weight')
            params['itemShippingCost%s' % i] = item.get('shipping_cost')

        if self.payment:

            params['paymentMethod'] = self.payment.get('method')
            params['paymentMode'] = self.payment.get('mode')

        if self.credit_card:
            params['billingAddressCountry'] = 'BRA'

            credit_card_keys_map = [
                ('creditCardToken', 'credit_card_token'),
                ('installmentQuantity', 'installment_quantity'),
                ('installmentValue', 'installment_value'),
                ('noInterestInstallmentQuantity',
                 'no_interest_installment_quantity'),
                ('creditCardHolderName', 'card_holder_name'),
                ('creditCardHolderCPF', 'card_holder_cpf'),
                ('creditCardHolderBirthDate', 'card_holder_birth_date'),
                ('creditCardHolderAreaCode', 'card_holder_area_code'),
                ('creditCardHolderPhone', 'card_holder_phone'),
                ('billingAddressStreet', 'billing_address_street'),
                ('billingAddressNumber', 'billing_address_number'),
                ('billingAddressComplement', 'billing_address_complement'),
                ('billingAddressDistrict', 'billing_address_district'),
                ('billingAddressPostalCode', 'billing_address_postal_code'),
                ('billingAddressCity', 'billing_address_city'),
                ('billingAddressState', 'billing_address_state'),
            ]

            for key_to_set, key_to_get in credit_card_keys_map:
                params[key_to_set] = self.credit_card.get(key_to_get)

        if self.pre_approval:

            params['preApprovalCharge'] = self.pre_approval.get('charge')
            params['preApprovalName'] = self.pre_approval.get('name')
            params['preApprovalDetails'] = self.pre_approval.get('details')
            params['preApprovalAmountPerPayment'] = self.pre_approval.get(
                'amount_per_payment')
            params['preApprovalMaxAmountPerPayment'] = self.pre_approval.get(
                'max_amount_per_payment')
            params['preApprovalPeriod'] = self.pre_approval.get('period')
            params['preApprovalMaxPaymentsPerPeriod'] = self.pre_approval.get(
                'max_payments_per_period')
            params['preApprovalMaxAmountPerPeriod'] = self.pre_approval.get(
                'max_amount_per_period')
            params['preApprovalInitialDate'] = self.pre_approval.get(
                'initial_date')
            params['preApprovalFinalDate'] = self.pre_approval.get(
                'final_date')
            params['preApprovalMaxTotalAmount'] = self.pre_approval.get(
                'max_total_amount')

        self.data.update(params)
        self.clean_none_params()
1248891
public function getPk($options = '')
    {
        if (!empty($this->pk)) {
            $pk = $this->pk;
        } else {
            $pk = $this->getTableInfo(is_array($options) ? $options['table'] : $options, 'pk');
        }
        return $pk;
    }
695494
protected function _getShippingId()
    {
        /** @var OxpsPaymorrowOxBasket|oxBasket $this */

        $sId = (string) $this->getShippingId();

        if ( !empty( $sId ) ) {
            $sId = $this->_toUtf( $sId );
        } else {
            $sId = 'shippingCosts';
        }

        return $sId;
    }
1129512
public function getOnShippingOptionsComplete($storeId = null)
    {
        return $this->getScopeConfig()->getValue(
            self::XML_PATH_TRACK_SHIPPING_OPTIONS_COMPLETE,
            ScopeInterface::SCOPE_STORE,
            $storeId
        );
    }
1020708
public function PostageForm()
    {
        if (!Checkout::config()->simple_checkout && $this->isDeliverable()) {
            $available_postage = Session::get("Checkout.AvailablePostage");
            
            // Setup form
            $form = Form::create(
                $this,
                'PostageForm',
                $fields = new FieldList(
                    CountryDropdownField::create(
                        'Country',
                        _t('Checkout.Country', 'Country')
                    ),
                    TextField::create(
                        "ZipCode",
                        _t('Checkout.ZipCode', "Zip/Postal Code")
                    )
                ),
                $actions = new FieldList(
                    FormAction::create(
                        "doSetPostage",
                        _t('Checkout.Search', "Search")
                    )->addExtraClass('btn')
                    ->addExtraClass('btn btn-green btn-success')
                ),
                $required = RequiredFields::create(array(
                    "Country",
                    "ZipCode"
                ))
            )->addExtraClass('forms')
            ->addExtraClass('forms-inline')
            ->setLegend(_t("Checkout.EstimateShipping", "Estimate Shipping"));


            // If we have stipulated a search, then see if we have any results
            // otherwise load empty fieldsets
            if ($available_postage && $available_postage->exists()) {
                // Loop through all postage areas and generate a new list
                $postage_array = array();
                
                foreach ($available_postage as $area) {
                    $area_currency = new Currency("Cost");
                    if ($this->IncludesTax()) {
                        $area_currency->setValue($area->Total());
                    } else {
                        $area_currency->setValue($area->Cost);
                    }
                    $postage_array[$area->ID] = $area->Title . " (" . $area_currency->Nice() . ")";
                }

                $fields->add(OptionsetField::create(
                    "PostageID",
                    _t('Checkout.SelectPostage', "Select Postage"),
                    $postage_array
                ));

                $actions
                    ->dataFieldByName("action_doSetPostage")
                    ->setTitle(_t('Checkout.Update', "Update"));
            }

            // Check if the form has been re-posted and load data
            $data = Session::get("Form.{$form->FormName()}.data");
            if (is_array($data)) {
                $form->loadDataFrom($data);
            }

            // Check if the postage area has been set, if so, Set Postage ID
            $data = array();
            $data["PostageID"] = Session::get("Checkout.PostageID");
            if (is_array($data)) {
                $form->loadDataFrom($data);
            }

            // Extension call
            $this->extend("updatePostageForm", $form);

            return $form;
        }
    }
203245
private function post_type_options()
    {
        $args = array( 'public' => true );
        $post_types = get_post_types($args, 'objects');
        $output = array();
        foreach ($post_types as $post_type) {
            $output[] = array(
                'value' => $post_type->name,
                'label' => $post_type->label
            );
        }
        return $output;
    }
670577
function flat() {
      global $order, $db;

      $this->code = 'flat';
      $this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_FLAT_TAX_BASIS;

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);
      }

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
            $check_flag = true;
            break;
          }
          $check->MoveNext();
        }

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }
    }
565397
function freeoptions() {
      global $order, $db;

      $this->code = 'freeoptions';
      $this->title = MODULE_SHIPPING_FREEOPTIONS_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_FREEOPTIONS_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_FREEOPTIONS_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_FREEOPTIONS_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_FREEOPTIONS_TAX_BASIS;

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
          $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
      }

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FREEOPTIONS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
            $check_flag = true;
            break;
          }
		  $check->MoveNext();
        }

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }
    }
349080
protected function buildShipmentArray(
        array $sender,
        array $destination,
        array $parcel,
        array $options = []
    ) {
        $this->formatPostalCode($sender['address-details']['postal-zip-code']);
        $this->formatPostalCode($destination['address-details']['postal-zip-code']);
        $shipment_info = [
            'requested-shipping-point' => $destination['address-details']['postal-zip-code'],
            'cpc-pickup-indicator' => true,
            'delivery-spec' => [
                'service-code' => $parcel['service_code'],
                'sender' => $sender,
                'destination' => $destination,
                'parcel-characteristics' => $parcel,
                'preferences' => [
                    'show-packing-instructions' => $options['packing_instructions'] ?? true,
                ],
                'notification' => [],
                'settlement-info' => [
                    'contract-id' => '',
                    'intended-method-of-payment' => 'Account',
                ],
            ],
        ];

        if (!empty($options['option_codes'])) {
            $shipment_info['options']['option'] = $this->parseOptionCodes($options);
        }

        return $shipment_info;
    }
1200695
public function getFilterOptions(array $options = array()) {
		$options['types'] = $this->comment->getType();
		$options['subtypes'] = array($this->comment->getSubtype(), 'hjcomment');
		$options['container_guids'] = $this->comment->container_guid;
		if (!isset($options['order_by'])) {
			$options['order_by'] = 'e.guid ASC';
		}
		return $options;
	}
1171261
private function getAllowedShippingCountriesRaw()
    {
        $allowedCountries = array_fill_keys($this->mainShipHelper->getMageShippingCountries(), []);
        $carriers         = $this->mainShipHelper->getActiveCarriers();
        $countries        = [];

        /**
         * @var AbstractCarrier $carrier
         */
        foreach ($carriers as $carrier) {
            /* skip shopgate cause its a container carrier */
            if ($carrier->getCarrierCode() === Shipping\Carrier\Shopgate::CODE) {
                continue;
            }

            /* if any carrier is using the allowed_countries collection, merge this into the result */
            if ($carrier->getConfigData('sallowspecific') === '0') {
                $countries = array_merge_recursive($countries, $allowedCountries);
                continue;
            }

            /* fetching active shipping targets from rates direct from the database */
            if ($carrier->getCarrierCode() === Shipping\Carrier\TableRate::CODE) {
                $collection    = $this->tableRate->getTableRateCollection();
                $countryHolder = [];

                /** @var Tablerate $rate */
                foreach ($collection as $rate) {
                    $countryHolder[$rate->getData('dest_country_id')][$rate->getData('dest_region') ? : 'All'] = true;
                }
                $countries = array_merge_recursive($countryHolder, $countries);
                continue;
            }

            $specificCountries = $carrier->getConfigData('specificcountry');
            $countries         = array_merge_recursive(
                $countries,
                array_fill_keys(explode(",", $specificCountries), [])
            );
        }

        foreach ($countries as $countryCode => $item) {
            if (!isset($allowedCountries[$countryCode])) {
                unset($countries[$countryCode]);
            }
        }

        return $countries;
    }
270405
def shipping_options(request, country):
    
    qrs = models.ShippingRate.objects.filter(countries__in=[country])
    serializer = serializers.ShippingRateSerializer(qrs, many=True)
    return Response(
        data=serializer.data,
        status=status.HTTP_200_OK
    )
1267620
private function _getShippingTypeFromStdIn() 
    {
        print PHP_EOL . "Select a shipping option for the order:" . PHP_EOL;
        print "\t 1 - Overnight shipping" . PHP_EOL;
        print "\t 2 - 2-day shipping" . PHP_EOL;
        print "\t 3 - 5-day shipping" . PHP_EOL;
        print ">>";

        do {
            $shippingType = trim(fgets(STDIN));
        } while (!is_numeric($shippingType) and 
                ($shippingType < 1 or $shippingType > 3));

        return $shippingType - 1;
    }
1311589
public function getAllowedShippingCountries()
    {
        $allowedShippingCountriesRaw = $this->getAllowedShippingCountriesRaw();
        $allowedShippingCountries    = [];

        foreach ($allowedShippingCountriesRaw as $countryCode => $states) {
            $states = empty($states) ? ['All' => true] : $states;
            $states = array_filter(
                array_keys($states),
                function ($st) {
                    return is_string($st) ? $st : 'All';
                }
            );

            $states = in_array('All', $states, true) ? ['All'] : $states;

            array_walk(
                $states,
                function (&$state, $key, $country) {
                    $state = $state === 'All' ? $state : $country . '-' . $state;
                },
                $countryCode
            );

            $allowedShippingCountries[] =
                [
                    'country' => $countryCode,
                    'state'   => $states
                ];
        }

        return $allowedShippingCountries;
    }
327023
public function __toJson($options = JSON_PRETTY_PRINT, $depth = 512)
    {
        $depth = $depth == 0 ? 512 : $depth;

        return call_user_func_array('json_encode', [$this->getArrayCopy(), $options, $depth]);
    }