本文整理汇总了PHP中Mage_Shipping_Model_Rate_Request::getPackageValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Shipping_Model_Rate_Request::getPackageValue方法的具体用法?PHP Mage_Shipping_Model_Rate_Request::getPackageValue怎么用?PHP Mage_Shipping_Model_Rate_Request::getPackageValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Shipping_Model_Rate_Request
的用法示例。
在下文中一共展示了Mage_Shipping_Model_Rate_Request::getPackageValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setRequest
/**
* Sets the request with new values where required for shipping calculation
*
* @param Mage_Shipping_Model_Rate_Request $request
*/
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$freeShippingOnly = 0;
$this->oldWeight = $request->getPackageWeight();
$this->oldQty = $request->getPackageQty();
$this->oldPrice = $request->getPackageValue();
$request->setPRConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name);
$this->_rawRequest = $request;
//Exclude virtual products price from package value if pre-configured
if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal());
}
}
} elseif ($item->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
}
}
}
$this->_rawRequest->setIgnoreFreeItems(false);
}
示例2: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
//Desabilitado
return false;
}
$result = Mage::getModel('shipping/rate_result');
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title'));
$packagevalue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
$frompcode = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
$topcode = $request->getDestPostcode();
// if(!preg_match("/^[0-9]{8}$/", $topcode))
// {
// //CEP está errado
// $error->setErrorMessage('O CEP está errado');
// $result->append($error);
// Mage::helper('customer')->__('Invalid ZIP CODE');
// return $result;
// }
//die('dfgf');
$sweight = $request->getPackageWeight();
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('name'));
$method->setMethod('sedex');
$method->setMethodTitle('Sedex');
$method->setPrice(10 + $this->getConfigData('handling_fee'));
$method->setCost(10);
$result->append($method);
$this->_result = $result;
$this->_updateFreeMethodQuote($request);
return $this->_result;
}
示例3: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
// skip if not enabled
if (!$this->isActive()) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
$handling = 0;
if (Mage::getStoreConfig('carriers/' . $this->_code . '/handling') > 0) {
$handling = Mage::getStoreConfig('carriers/' . $this->_code . '/handling');
}
if (Mage::getStoreConfig('carriers/' . $this->_code . '/handling_type') == 'P' && $request->getPackageValue() > 0) {
$handling = $request->getPackageValue() * $handling;
}
$requestClone = clone $request;
$result = $this->getResult($request);
return $result;
// it doesnt do anything if there was an error just returns blank - maybe there should be a default shipping incase of problem? or email sysadmin?
}
示例4: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
return false;
}
$lei = Mage::helper('urgent')->isLei($request->getData('package_currency'));
if (!$lei) {
return false;
}
$helper = Mage::helper('urgent');
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal());
}
}
} elseif ($item->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
}
}
}
$valuare = $request->getPackageValue() * $lei;
if ($helper->getAfisare() == 2) {
$methodUrgent = $this->_calculateTotal($request, $valuare, true);
$result = Mage::getModel('shipping/rate_result');
$result->append($methodUrgent);
return $result;
} else {
$methodUrgent = $this->_calculateTotal($request, $valuare, false);
$result = Mage::getModel('shipping/rate_result');
$result->append($methodUrgent);
return $result;
}
}
示例5: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->isActive()) {
return false;
}
$valids = $this->getConfigData('aceita');
if ($valids == 'AMBOS') {
$valids = array('PAC', 'Sedex');
} else {
$valids = array($valids);
}
$result = Mage::getModel('shipping/rate_result');
$method = Mage::getModel('shipping/rate_result_method');
$peso = $request->getPackageWeight();
$destino = $request->getDestPostcode();
$valor = $request->getPackageValue();
$frete = $this->pegaFrete($peso, $destino, $valor);
// Peso, destino, valor
if (in_array('Sedex', $valids)) {
$method->setCarrier($this->_code);
$method->setCarrierTitle('PagSeguro');
$method->setMethod($this->_code . ':Sedex');
$method->setMethodTitle('Sedex');
$method->setPrice($frete['Sedex']);
$result->append($method);
}
// Setando valores para PAC
if (in_array('PAC', $valids)) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setCarrierTitle('PagSeguro');
$method->setMethod($this->_code . ':PAC');
$method->setMethodTitle('PAC');
$method->setPrice($frete['PAC']);
$result->append($method);
}
/*
}else{
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$error->setCarrierTitle("PagSeguro");
$error->setErrorMessage(utf8_encode($frete));
return $error;
}*/
return $result;
}
示例6: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$cep = $request->getDestPostcode();
$totalPedido = $request->getPackageValue();
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('active') && (!$this->getConfigData('valor_pedido') || $totalPedido >= $this->getConfigData('valor_pedido'))) {
if ($this->cepNaFaixa($cep) && $this->getConfigData('frete_gratis_por_faixa') || !$this->getConfigData('frete_gratis_por_faixa')) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($this->_code);
$method->setMethodTitle($this->_name);
$method->setPrice('0.00');
$method->setCost('0.00');
$result->append($method);
}
}
return $result;
}
示例7: collectRates
/**
* Enter description here...
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
$packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
$allow = $request->getFreeShipping() || $packageValue >= $this->getConfigData('cutoff_cost');
if ($allow) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('freeshipping');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('freeshipping');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice('0.00');
$method->setCost('0.00');
$result->append($method);
}
return $result;
}
示例8: collectRates
/**
* Enter description here...
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$allow = $request->getmultiflat();
$result = Mage::getModel('shipping/rate_result');
$packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
for ($i = 0; $i <= 10; $i++) {
if ($this->getConfigData('type' . $i) == 'O') {
// per order
$shippingPrice = $this->getConfigData('price' . $i);
} elseif ($this->getConfigData('type' . $i) == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price' . $i) - $this->getFreeBoxes() * $this->getConfigData('price' . $i);
} else {
$shippingPrice = $this->getConfigData('price' . $i);
}
$shippingName = $this->getConfigData('name' . $i);
if ($shippingName != "" && ($packageValue >= $this->getConfigData('min_shipping' . $i) && $packageValue <= $this->getConfigData('max_shipping' . $i)) or $shippingName != "" && $this->getConfigData('max_shipping' . $i) == "") {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('msmultiflat');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($this->getConfigData('name' . $i));
$method->setMethodTitle($this->getConfigData('name' . $i));
$method->setMethodDetails($this->getConfigData('details' . $i));
$method->setMethodDescription($this->getConfigData('details' . $i));
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
} else {
if ($shippingName == "") {
}
}
}
return $result;
}
示例9: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$result = Mage::getModel('shipping/rate_result');
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$cepdest = $request->getDestPostcode();
$cepdest = str_replace('-', '', $cepdest);
$value = $request->getPackageValue();
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$collection = Mage::getModel('motoboyconfig/motoboyconfig')->getCollection();
$collection->addFieldToFilter('cepinicial', array('lteq' => $cepdest));
$collection->addFieldToFilter('cepfinal', array('gteq' => $cepdest));
$frete = $collection->getFirstItem();
if ($frete->getData('valor_pedido')) {
$valor = $frete->getData('valor_pedido');
$prazo = $frete->getData('prazo');
$method->setMethodTitle($this->getConfigData('name') . ' - <font color="red"> ' . $prazo . ' dias para entrega </font>');
$method->setPrice($valor);
$method->setCost($valor);
$result->append($method);
}
return $result;
}
示例10: getRate
public function getRate(Mage_Shipping_Model_Rate_Request $request)
{
$read = $this->_getReadAdapter();
$postcode = $request->getDestPostcode();
$table = $this->getMainTable();
$storeId = $request->getStoreId();
$insuranceStep = (double) Mage::getStoreConfig('carriers/eparcel/insurance_step', $storeId);
$insuranceCostPerStep = (double) Mage::getStoreConfig('carriers/eparcel/insurance_cost_per_step', $storeId);
$signatureRequired = Mage::getStoreConfigFlag('carriers/eparcel/signature_required', $storeId);
if ($signatureRequired) {
$signatureCost = (double) Mage::getStoreConfig('carriers/eparcel/signature_cost', $storeId);
} else {
$signatureCost = 0;
}
for ($j = 0; $j < 5; $j++) {
$select = $read->select()->from($table);
// Support for Multi Warehouse Extension.
if ($request->getWarehouseId() > 0) {
$select->where('stock_id = ?', $request->getWarehouseId());
}
switch ($j) {
case 0:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? ", $request->getDestRegionId()) . $read->quoteInto(" AND dest_zip=?) ", $postcode));
break;
case 1:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? AND dest_zip='0000') ", $request->getDestRegionId()));
break;
case 2:
$select->where($read->quoteInto(" (dest_country_id=? AND dest_region_id='0' AND dest_zip='0000') ", $request->getDestCountryId()));
break;
case 3:
$select->where($read->quoteInto(" (dest_country_id=? AND dest_region_id='0' ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_zip=?) ", $postcode));
break;
case 4:
$select->where(" (dest_country_id='0' AND dest_region_id='0' AND dest_zip='0000')");
break;
}
if (is_array($request->getConditionName())) {
$i = 0;
foreach ($request->getConditionName() as $conditionName) {
if ($i == 0) {
$select->where('condition_name=?', $conditionName);
} else {
$select->orWhere('condition_name=?', $conditionName);
}
$select->where('condition_from_value<=?', $request->getData($conditionName));
$select->where('condition_to_value>=?', $request->getData($conditionName));
$i++;
}
} else {
$select->where('condition_name=?', $request->getConditionName());
$select->where('condition_from_value<=?', $request->getData($request->getConditionName()));
$select->where('condition_to_value>=?', $request->getData($request->getConditionName()));
}
$select->where('website_id=?', $request->getWebsiteId());
$select->order('dest_country_id DESC');
$select->order('dest_region_id DESC');
$select->order('dest_zip DESC');
$select->order('condition_from_value DESC');
// pdo has an issue. we cannot use bind
$newdata = array();
$row = $read->fetchAll($select);
if (!empty($row) && $j < 5) {
// have found a result or found nothing and at end of list!
foreach ($row as $data) {
try {
$price = (double) $data['price'];
// add per-Kg cost
$conditionValue = (double) $request->getData($request->getConditionName());
$price += (double) $data['price_per_kg'] * $conditionValue;
// add signature cost
$price += $signatureCost;
// add version without insurance
$data['price'] = (string) $price;
$newdata[] = $data;
if (Mage::getStoreConfig('carriers/eparcel/insurance_enable', $storeId)) {
// add version with insurance
// work out how many insurance 'steps' we have
$steps = ceil($request->getPackageValue() / $insuranceStep);
// add on number of 'steps' multiplied by the
// insurance cost per step
$insuranceCost = $insuranceCostPerStep * $steps;
$price += $insuranceCost;
$data['price'] = (string) $price;
$data['delivery_type'] .= " with TransitCover";
$newdata[] = $data;
}
} catch (Exception $e) {
Mage::log($e->getMessage());
}
}
break;
}
}
return $newdata;
}
示例11: _inicialCheck
/**
* Make initial checks and iniciate module variables
*
* @param Mage_Shipping_Model_Rate_Request $request Mage request
*
* @return bool
*/
protected function _inicialCheck(Mage_Shipping_Model_Rate_Request $request)
{
$this->_prepareProductsToSendFastShipping();
$this->_fromZip = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
$this->_toZip = $request->getDestPostcode();
// Fix ZIP code
$this->_fromZip = str_replace(array('-', '.'), '', trim($this->_fromZip));
$this->_toZip = str_replace(array('-', '.'), '', trim($this->_toZip));
$this->_result = Mage::getModel('shipping/rate_result');
$this->_packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
$this->_packageWeight = number_format($request->getPackageWeight(), 2, '.', '');
$this->_freeMethodWeight = number_format($request->getFreeMethodWeight(), 2, '.', '');
}
示例12: collectRates
/**
* Collect and get rates
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
// exclude Virtual products price from Package value if pre-configured
if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal());
}
}
} elseif ($item->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
}
}
}
// Free shipping by qty
$freeQty = 0;
if ($request->getAllItems()) {
$freePackageValue = 0;
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0;
$freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
}
}
} elseif ($item->getFreeShipping()) {
$freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0;
$freeQty += $item->getQty() - $freeShipping;
$freePackageValue += $item->getBaseRowTotal();
}
}
$oldValue = $request->getPackageValue();
$request->setPackageValue($oldValue - $freePackageValue);
}
if ($freePackageValue) {
$request->setPackageValue($request->getPackageValue() - $freePackageValue);
}
if (!$request->getConditionName()) {
$conditionName = $this->getConfigData('condition_name');
$request->setConditionName($conditionName ? $conditionName : $this->_default_condition_name);
}
// Package weight and qty free shipping
$oldWeight = $request->getPackageWeight();
$oldQty = $request->getPackageQty();
$request->setPackageWeight($request->getFreeMethodWeight());
$request->setPackageQty($oldQty - $freeQty);
$result = $this->_getModel('shipping/rate_result');
$rate = $this->getRate($request);
$request->setPackageWeight($oldWeight);
$request->setPackageQty($oldQty);
if (!empty($rate) && $rate['price'] >= 0) {
$method = $this->_getModel('shipping/rate_result_method');
$method->setCarrier('tablerate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('bestway');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {
$shippingPrice = 0;
} else {
$shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
}
$method->setPrice($shippingPrice);
$method->setCost($rate['cost']);
$result->append($method);
} elseif (empty($rate) && $request->getFreeShipping() === true) {
/**
* was applied promotion rule for whole cart
* other shipping methods could be switched off at all
* we must show table rate method with 0$ price, if grand_total more, than min table condition_value
* free setPackageWeight() has already was taken into account
*/
$request->setPackageValue($freePackageValue);
$request->setPackageQty($freeQty);
$rate = $this->getRate($request);
if (!empty($rate) && $rate['price'] >= 0) {
$method = $this->_getModel('shipping/rate_result_method');
$method->setCarrier('tablerate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('bestway');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice(0);
$method->setCost(0);
//.........这里部分代码省略.........
示例13: setRequest
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
$r->setStoreId($request->getStoreId());
if ($request->getLimitMethod()) {
$r->setService($request->getLimitMethod());
}
if ($request->getDhlId()) {
$id = $request->getDhlId();
} else {
$id = $this->getConfigData('id');
}
$r->setId($id);
if ($request->getDhlPassword()) {
$password = $request->getDhlPassword();
} else {
$password = $this->getConfigData('password');
}
$r->setPassword($password);
if ($request->getDhlAccount()) {
$accountNbr = $request->getDhlAccount();
} else {
$accountNbr = $this->getConfigData('account');
}
$r->setAccountNbr($accountNbr);
if ($request->getDhlShippingKey()) {
$shippingKey = $request->getDhlShippingKey();
} else {
$shippingKey = $this->getConfigData('shipping_key');
}
$r->setShippingKey($shippingKey);
if ($request->getDhlShippingIntlKey()) {
$shippingKey = $request->getDhlShippingIntlKey();
} else {
$shippingKey = $this->getConfigData('shipping_intlkey');
}
$r->setShippingIntlKey($shippingKey);
if ($request->getDhlShipmentType()) {
$shipmentType = $request->getDhlShipmentType();
} else {
$shipmentType = $this->getConfigData('shipment_type');
}
$r->setShipmentType($shipmentType);
if ($request->getDhlDutiable()) {
$shipmentDutible = $request->getDhlDutiable();
} else {
$shipmentDutible = $this->getConfigData('dutiable');
}
$r->setDutiable($shipmentDutible);
if ($request->getDhlDutyPaymentType()) {
$dutypaytype = $request->getDhlDutyPaymentType();
} else {
$dutypaytype = $this->getConfigData('dutypaymenttype');
}
$r->setDutyPaymentType($dutypaytype);
if ($request->getDhlContentDesc()) {
$contentdesc = $request->getDhlContentDesc();
} else {
$contentdesc = $this->getConfigData('contentdesc');
}
$r->setContentDesc($contentdesc);
if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
}
if ($request->getOrigCountry()) {
$origCountry = $request->getOrigCountry();
} else {
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
}
$r->setOrigCountry($origCountry);
/*
* DHL only accepts weight as a whole number. Maximum length is 3 digits.
*/
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
$shippingWeight = round(max(1, $weight), 0);
$r->setValue(round($request->getPackageValue(), 2));
$r->setValueWithDiscount($request->getPackageValueWithDiscount());
$r->setDestStreet(Mage::helper('core/string')->substr($request->getDestStreet(), 0, 35));
$r->setDestCity($request->getDestCity());
if ($request->getDestCountryId()) {
$destCountry = $request->getDestCountryId();
} else {
$destCountry = self::USA_COUNTRY_ID;
}
//for DHL, puero rico state for US will assume as puerto rico country
//for puerto rico, dhl will ship as international
if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
$destCountry = self::PUERTORICO_COUNTRY_ID;
}
$r->setDestCountryId($destCountry);
$r->setDestState($request->getDestRegionCode());
$r->setWeight($shippingWeight);
$r->setFreeMethodWeight($request->getFreeMethodWeight());
$this->_rawRequest = $r;
// $methods = explode(',', $this->getConfigData('allowed_methods'));
//
// $freeMethod = $this->getConfigData('free_method');
//
// $internationcode = $this->getCode('international_searvice');
//.........这里部分代码省略.........
示例14: process
public function process(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
if ($request->getLimitMethod()) {
$r->setService($request->getLimitMethod());
}
if ($request->getDhlId()) {
$id = $request->getDhlId();
} else {
$id = $this->getConfigData('id');
}
$r->setId($id);
if ($request->getDhlPassword()) {
$password = $request->getDhlPassword();
} else {
$password = $this->getConfigData('password');
}
$r->setPassword($password);
if ($request->getDhlAccount()) {
$accountNbr = $request->getDhlAccount();
} else {
$accountNbr = $this->getConfigData('account');
}
$r->setAccountNbr($accountNbr);
if ($request->getDhlShippingKey()) {
$shippingKey = $request->getDhlShippingKey();
} else {
$shippingKey = $this->getConfigData('shipping_key');
}
$r->setShippingKey($shippingKey);
if ($request->getDhlShippingIntlKey()) {
$shippingKey = $request->getDhlShippingIntlKey();
} else {
$shippingKey = $this->getConfigData('shipping_intlkey');
}
$r->setShippingIntlKey($shippingKey);
if ($request->getDhlShipmentType()) {
$shipmentType = $request->getDhlShipmentType();
} else {
$shipmentType = $this->getConfigData('shipment_type');
}
$r->setShipmentType($shipmentType);
if ($request->getDhlDutiable()) {
$shipmentDutible = $request->getDhlDutiable();
} else {
$shipmentDutible = $this->getConfigData('dutiable');
}
$r->setDutiable($shipmentDutible);
if ($request->getDhlDutyPaymentType()) {
$dutypaytype = $request->getDhlDutyPaymentType();
} else {
$dutypaytype = $this->getConfigData('dutypaymenttype');
}
$r->setDutyPaymentType($dutypaytype);
if ($request->getDhlContentDesc()) {
$contentdesc = $request->getDhlContentDesc();
} else {
$contentdesc = $this->getConfigData('contentdesc');
}
$r->setContentDesc($contentdesc);
if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
}
if ($request->getOrigCountry()) {
$origCountry = $request->getOrigCountry();
} else {
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
}
$r->setOrigCountry($origCountry);
/*
* DHL only accepts weight as a whole number. Maximum length is 3 digits.
*/
$shippingWeight = round(min(1, $request->getPackageWeight()), 0);
$freeMethodWeight = round(min(1, $request->getFreeMethodWeight()), 0);
$r->setValue(round($request->getPackageValue(), 2));
$r->setDestStreet(substr($request->getDestStreet(), 0, 35));
$r->setDestCity($request->getDestCity());
$r->setDestCountryId($request->getDestCountryId());
$r->setDestState($request->getDestRegionCode());
$this->_rawRequest = $r;
$methods = explode(',', $this->getConfigData('allowed_methods'));
$freeMethod = $this->getConfigData('free_method');
$internationcode = $this->getCode('international_searvice');
foreach ($methods as $method) {
if ($method == $internationcode && $r->getDestCountryId() != self::USA_COUNTRY_ID || $method != $internationcode && $r->getDestCountryId() == self::USA_COUNTRY_ID) {
$weight = $freeMethod == $method ? $freeMethodWeight : $shippingWeight;
if ($weight > 0) {
$this->_rawRequest->setWeight($weight);
$this->_rawRequest->setService($method);
$this->_getQuotes();
} else {
$this->_dhlRates[$method] = array('term' => $this->getCode('service', $method), 'price_total' => 0);
}
}
}
return $this;
}
示例15: collectRates
/**
* Collect shipping method price and set all data selected in config.
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return bool|false|Mage_Core_Model_Abstract
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
return false;
}
$method = Mage::getModel('shipping/rate_result_method');
$result = Mage::getModel('shipping/rate_result');
if (!$this->getConfigData('ratetype')) {
$price = $this->getConfigData('flatrateprice');
if ($request->getFreeShipping() === true) {
$price = 0;
}
} else {
$freeQty = 0;
if ($request->getAllItems()) {
$freePackageValue = 0;
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0;
$freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
}
}
} elseif ($item->getFreeShipping()) {
$freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0;
$freeQty += $item->getQty() - $freeShipping;
$freePackageValue += $item->getBaseRowTotal();
}
}
$oldValue = $request->getPackageValue();
$request->setPackageValue($oldValue - $freePackageValue);
}
if ($freePackageValue) {
$request->setPackageValue($request->getPackageValue() - $freePackageValue);
}
$conditionName = $this->getConfigData('condition_name');
$request->setConditionName($conditionName ? $conditionName : $this->_default_condition_name);
$oldWeight = $request->getPackageWeight();
$oldQty = $request->getPackageQty();
$request->setPackageWeight($request->getFreeMethodWeight());
$request->setPackageQty($oldQty - $freeQty);
$rate = $this->getRate($request);
$request->setPackageWeight($oldWeight);
$request->setPackageQty($oldQty);
if (!empty($rate) && $rate['price'] >= 0) {
if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {
$price = 0;
} else {
$price = $rate['price'];
}
} elseif (empty($rate) && $request->getFreeShipping() === true) {
$request->setPackageValue($freePackageValue);
$request->setPackageQty($freeQty);
$rate = $this->getRate($request);
if (!empty($rate) && $rate['price'] >= 0) {
$price = 0;
}
} else {
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title'));
$error->setErrorMessage(Mage::helper('dpd')->__('This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.'));
$result->append($error);
return $result;
}
}
$method->setCarrier($this->_code);
$method->setMethod($this->_code);
$method->setMethodTitle($this->getConfigData('name'));
$method->setCarrierTitle($this->getConfigData('carrier'));
$method->setPrice($price);
$method->setCost($price);
$result->append($method);
return $result;
}