当前位置: 首页>>代码示例>>PHP>>正文


PHP Converter::convertWeightUnits方法代码示例

本文整理汇总了PHP中XLite\Core\Converter::convertWeightUnits方法的典型用法代码示例。如果您正苦于以下问题:PHP Converter::convertWeightUnits方法的具体用法?PHP Converter::convertWeightUnits怎么用?PHP Converter::convertWeightUnits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XLite\Core\Converter的用法示例。


在下文中一共展示了Converter::convertWeightUnits方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: callCreateAuthorizedReturnByProductsReturn

    /**
     * Call "Create Authorized Return" request by the ProductsReturn model
     *
     * @param \XLite\Module\XC\CanadaPost\Model\ProductsReturn $return Canada Post return model
     *
     * @return \XLite\Core\CommonCell
     */
    public function callCreateAuthorizedReturnByProductsReturn(\XLite\Module\XC\CanadaPost\Model\ProductsReturn $return)
    {
        $xmlHeader = '<' . '?xml version="1.0" encoding="utf-8"?' . '>';
        // Convert weight into KG
        $itemsWeight = \XLite\Core\Converter::convertWeightUnits($return->getItemsTotalWeight(), \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg');
        $itemsWeight = static::adjustFloatValue($itemsWeight, 3, 0.1, 999.999);
        $requestData = <<<XML
{$xmlHeader}
<authorized-return xmlns="http://www.canadapost.ca/ws/authreturn-v2">
    <service-code>{$return->getOrder()->getCapostShippingMethodCode()}</service-code>
{$this->getXmlBlockReturnerAddress($return->getOrder()->getProfile())}
{$this->getXmlBlockReceiverAddress()}
    <parcel-characteristics>
        <weight>{$itemsWeight}</weight>
    </parcel-characteristics>
    <print-preferences>
        <output-format>8.5x11</output-format>
        <encoding>PDF</encoding>
    </print-preferences>
    <settlement-info></settlement-info>
</authorized-return>
XML;
        return $this->callCreateAuthorizedReturn($requestData);
    }
开发者ID:kirkbauer2,项目名称:kirkxc,代码行数:31,代码来源:Returns.php

示例2: prepareInputData

 /**
  * prepareInputData
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  *
  * @return void
  */
 protected function prepareInputData(\XLite\Logic\Order\Modifier\Shipping $modifier)
 {
     $result = null;
     // Fill $result array by data from the order
     if ('AU' == \XLite\Core\Config::getInstance()->Company->location_country) {
         $result['srcAddress']['zipcode'] = \XLite\Core\Config::getInstance()->Company->location_zipcode;
         $address = \XLite\Model\Shipping::getInstance()->getDestinationAddress($modifier);
         if (isset($address)) {
             $result['dstAddress'] = $address;
             $result['weight'] = \XLite\Core\Converter::convertWeightUnits($modifier->getWeight(), \XLite\Core\Config::getInstance()->General->weight_unit, 'g');
         } else {
             $result = null;
         }
     }
     return $result;
 }
开发者ID:kingsj,项目名称:core,代码行数:23,代码来源:AustraliaPost.php

示例3: getWeightInKg

 /**
  * Get single item weight in KG
  *
  * @param boolean $adjustFloatValue Flag - adjust float value or not (OPTIONAL)
  *
  * @return float
  */
 public function getWeightInKg($adjustFloatValue = false)
 {
     // Convert weight from store units to KG (weight must be in KG)
     $weight = \XLite\Core\Converter::convertWeightUnits($this->getWeight(), \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg');
     if ($adjustFloatValue) {
         // Adjust according to the XML element schema
         $weight = \XLite\Module\XC\CanadaPost\Core\Service\AService::adjustFloatValue($weight, 3, 0, 99.999);
     }
     return $weight;
 }
开发者ID:kewaunited,项目名称:xcart,代码行数:17,代码来源:Item.php

示例4: getPackageLimits

 /**
  * Get package limits
  *
  * @return array
  */
 protected function getPackageLimits()
 {
     $limits = parent::getPackageLimits();
     $config = $this->getConfiguration();
     // Weight in store weight units
     $limits['weight'] = \XLite\Core\Converter::convertWeightUnits($config->max_weight, 'kg', \XLite\Core\Config::getInstance()->Units->weight_unit);
     list($limits['length'], $limits['width'], $limits['height']) = $this->getPackageSize();
     return $limits;
 }
开发者ID:kirkbauer2,项目名称:kirkxc,代码行数:14,代码来源:AustraliaPost.php

示例5: getPoundsOunces

 /**
  * Returns array(pounds, ounces) from a weight value in specific weight units
  *
  * @param float $weight Weight value
  *
  * @return array
  */
 public function getPoundsOunces($weight)
 {
     $pounds = $ounces = 0;
     switch (\XLite\Core\Config::getInstance()->Units->weight_unit) {
         case 'lbs':
             $pounds = $weight;
             break;
         case 'oz':
             $ounces = $weight;
             break;
         default:
             $ounces = \XLite\Core\Converter::convertWeightUnits($weight, \XLite\Core\Config::getInstance()->Units->weight_unit, 'oz');
     }
     if (intval($pounds) < $pounds) {
         $ounces = ($pounds - intval($pounds)) * 16;
         $pounds = intval($pounds);
     }
     return array($pounds, round($ounces, 1));
 }
开发者ID:kewaunited,项目名称:xcart,代码行数:26,代码来源:USPS.php

示例6: prepareInputData

 /**
  * Returns array of data for request
  *
  * @param array|\XLite\Logic\Order\Modifier\Shipping $inputData Array of input data or a shipping order modifier
  *
  * @return array
  */
 protected function prepareInputData($inputData)
 {
     $data = array();
     $commonData = array();
     if ($inputData instanceof \XLite\Logic\Order\Modifier\Shipping) {
         if ('CA' == \XLite\Core\Config::getInstance()->Company->location_country) {
             $commonData['srcAddress'] = array('zipcode' => \XLite\Core\Config::getInstance()->Company->location_zipcode);
         }
         $commonData['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
         if (!empty($commonData['srcAddress']) && !empty($commonData['dstAddress'])) {
             $data['packages'] = $this->getPackages($inputData);
         }
     } else {
         $data = $inputData;
     }
     if (!empty($data['packages'])) {
         foreach ($data['packages'] as $key => $package) {
             $package = array_merge($package, $commonData);
             $package['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg');
             $package['subtotal'] = \XLite\Module\XC\CanadaPost\Core\API::applyConversionRate($package['subtotal']);
             $data['packages'][$key] = $package;
         }
     } else {
         $data = array();
     }
     return $data;
 }
开发者ID:kewaunited,项目名称:xcart,代码行数:34,代码来源:CanadaPost.php

示例7: prepareInputData

 /**
  * prepareInputData
  *
  * @param array|\XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier (from order) or array of input data (from test controller)
  *
  * @return void
  */
 protected function prepareInputData($inputData)
 {
     $data = array();
     if ($inputData instanceof \XLite\Logic\Order\Modifier\Shipping) {
         $data = $this->prepareDataFromModifier($inputData);
     } else {
         $data = $inputData;
     }
     if (!empty($data['packages'])) {
         $data['total'] = 0;
         list($wUnit, $dUnit) = static::getWeightAndDimUnits($data['srcAddress']['country']);
         foreach ($data['packages'] as $key => $package) {
             $data['packages'][$key]['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'KGS' == $wUnit ? 'kg' : 'lbs');
             $data['packages'][$key]['weight'] = max(0.1, $data['packages'][$key]['weight']);
             $data['packages'][$key]['subtotal'] = $this->getPackagesSubtotal($package['subtotal']);
             $data['total'] += $data['packages'][$key]['subtotal'];
         }
     } else {
         $data = array();
         $this->errorMsg = 'There are no defined packages to delivery';
     }
     return $this->getQuoted($data);
 }
开发者ID:kewaunited,项目名称:xcart,代码行数:30,代码来源:UPS.php

示例8: prepareRequestData

 /**
  * Returns array of data for request
  *
  * @param array|\XLite\Logic\Order\Modifier\Shipping $inputData Array of input data or a shipping order modifier
  *
  * @return array
  */
 protected function prepareRequestData($inputData)
 {
     $result = array();
     $data = array();
     $data['packages'] = array();
     if ($inputData instanceof \XLite\Logic\Order\Modifier\Shipping) {
         $data['srcAddress'] = array('zipcode' => \XLite\Core\Config::getInstance()->Company->location_zipcode, 'country' => \XLite\Core\Config::getInstance()->Company->location_country);
         if (isset(\XLite\Core\Config::getInstance()->Company->location_state)) {
             $data['srcAddress']['state'] = \XLite\Core\Database::getRepo('XLite\\Model\\State')->getCodeById(\XLite\Core\Config::getInstance()->Company->location_state);
         }
         $data['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
         if (empty($data['dstAddress']['country'])) {
             $data['dstAddress'] = null;
         } elseif (isset($data['dstAddress']['state'])) {
             $data['dstAddress']['state'] = \XLite\Core\Database::getRepo('XLite\\Model\\State')->getCodeById($data['dstAddress']['state']);
         }
         $data['packages'] = $this->getPackages($inputData);
         // Detect if COD payment method has been selected by customer on checkout
         if ($inputData->getOrder()->getFirstOpenPaymentTransaction()) {
             $paymentMethod = $inputData->getOrder()->getPaymentMethod();
             if ($paymentMethod && 'COD_FEDEX' == $paymentMethod->getServiceName()) {
                 $data['cod_enabled'] = true;
             }
         }
     } else {
         $data = $inputData;
     }
     if (!empty($data['packages']) && !empty($data['srcAddress']) && !empty($data['dstAddress'])) {
         $result = $data;
         $result['packages'] = array();
         foreach ($data['packages'] as $packKey => $package) {
             $package['price'] = sprintf('%.2f', $package['subtotal']);
             // decimal, min=0.00, totalDigits=10
             $package['weight'] = round(\XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'lbs'), 4);
             $result['packages'][] = $package;
         }
     }
     return $result;
 }
开发者ID:kewaunited,项目名称:xcart,代码行数:46,代码来源:FEDEX.php

示例9: prepareInputData

 /**
  * prepareInputData
  *
  * @param array|\XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier (from order) or
  *                                                              array of input data (from test controller)
  *
  * @return array
  */
 protected function prepareInputData($inputData)
 {
     if ($inputData instanceof \XLite\Logic\Order\Modifier\Shipping) {
         $data = $this->prepareDataFromModifier($inputData);
     } else {
         $data = $inputData;
     }
     if (!empty($data['packages'])) {
         foreach ($data['packages'] as $key => $package) {
             if (!$this->isDstCountryValid($package['country_code'])) {
                 $data = array();
                 $this->errorMsg = 'There are no delivery to the country ' . $package['country_code'];
                 break;
             }
             $data['packages'][$key]['shipment_type'] = 'AU' == $package['country_code'] ? 'Domestic' : 'International';
             $data['packages'][$key]['package_type'] = \XLite\Core\Config::getInstance()->CDev->AustraliaPost->package_type;
             $data['packages'][$key]['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg');
             $data['packages'][$key]['subtotal'] = $this->getPackagesSubtotal($package['subtotal']);
             if (isset($data['packages'][$key]['box'])) {
                 $length = $data['packages'][$key]['box']['length'];
                 $width = $data['packages'][$key]['box']['width'];
                 $height = $data['packages'][$key]['box']['height'];
             } else {
                 list($length, $width, $height) = $this->getAuspostPackageSizes();
             }
             $data['packages'][$key]['length'] = $length;
             $data['packages'][$key]['width'] = $width;
             $data['packages'][$key]['height'] = $height;
         }
     } else {
         $this->errorMsg = 'There are no defined packages to delivery';
     }
     return $data;
 }
开发者ID:kewaunited,项目名称:xcart,代码行数:42,代码来源:AustraliaPost.php

示例10: postProcessInputData

 /**
  * Post process input data
  *
  * @param array $inputData Prepared input data
  *
  * @return array
  */
 protected function postProcessInputData(array $inputData)
 {
     if (!empty($inputData['packages'])) {
         $inputData['total'] = 0;
         list($wUnit, ) = static::getWeightAndDimUnits($inputData['srcAddress']['country']);
         foreach ($inputData['packages'] as $key => $package) {
             $inputData['packages'][$key]['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'KGS' === $wUnit ? 'kg' : 'lbs');
             $inputData['packages'][$key]['weight'] = max(0.1, $inputData['packages'][$key]['weight']);
             $inputData['packages'][$key]['subtotal'] = $this->getPackagesSubtotal($package['subtotal']);
             $inputData['total'] += $inputData['packages'][$key]['subtotal'];
         }
     } else {
         $inputData = array();
     }
     return parent::postProcessInputData($inputData);
 }
开发者ID:kirkbauer2,项目名称:kirkxc,代码行数:23,代码来源:UPS.php


注:本文中的XLite\Core\Converter::convertWeightUnits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。