本文整理汇总了PHP中Mage_Shipping_Model_Rate_Request::getDestCountryId方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Shipping_Model_Rate_Request::getDestCountryId方法的具体用法?PHP Mage_Shipping_Model_Rate_Request::getDestCountryId怎么用?PHP Mage_Shipping_Model_Rate_Request::getDestCountryId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Shipping_Model_Rate_Request
的用法示例。
在下文中一共展示了Mage_Shipping_Model_Rate_Request::getDestCountryId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAvailableShipCountries
public function checkAvailableShipCountries(Mage_Shipping_Model_Rate_Request $request)
{
$speCountriesAllow = $this->getConfigData('sallowspecific');
/*
* for specific countries, the flag will be 1
*/
if ($speCountriesAllow && $speCountriesAllow == 1) {
$showMethod = $this->getConfigData('showmethod');
$availableCountries = array();
if ($this->getConfigData('specificcountry')) {
$availableCountries = explode(',', $this->getConfigData('specificcountry'));
}
if ($availableCountries && in_array($request->getDestCountryId(), $availableCountries)) {
return $this;
} elseif ($showMethod && (!$availableCountries || $availableCountries && !in_array($request->getDestCountryId(), $availableCountries))) {
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title'));
$errorMsg = $this->getConfigData('specificerrmsg');
$error->setErrorMessage($errorMsg ? $errorMsg : Mage::helper('shipping')->__('The shipping module is not available for selected delivery country'));
return $error;
} else {
/*
* The admin set not to show the shipping module if the devliery country is not within specific countries
*/
return false;
}
}
return $this;
}
示例2: setRequest
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
if ($request->getLimitMethod()) {
$r->setService($request->getLimitMethod());
}
if ($request->getFedexAccount()) {
$account = $request->getFedexAccount();
} else {
$account = $this->getConfigData('account');
}
$r->setAccount($account);
if ($request->getFedexDropoff()) {
$dropoff = $request->getFedexDropoff();
} else {
$dropoff = $this->getConfigData('dropoff');
}
$r->setDropoffType($dropoff);
if ($request->getFedexPackaging()) {
$packaging = $request->getFedexPackaging();
} else {
$packaging = $this->getConfigData('packaging');
}
$r->setPackaging($packaging);
if ($request->getOrigCountry()) {
$origCountry = $request->getOrigCountry();
} else {
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
}
$r->setOrigCountry(Mage::getModel('directory/country')->load($origCountry)->getIso2Code());
if ($request->getOrigPostcode()) {
$r->setOrigPostal($request->getOrigPostcode());
} else {
$r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()));
}
if ($request->getDestCountryId()) {
$destCountry = $request->getDestCountryId();
} else {
$destCountry = self::USA_COUNTRY_ID;
}
$r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code());
if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
} else {
}
$r->setWeight($request->getPackageWeight());
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
$r->setFreeMethodWeight($request->getFreeMethodWeight());
}
$r->setValue($request->getPackageValue());
$this->_rawRequest = $r;
return $this;
}
示例3: collectRates
/**
* Collects the shipping rates for Australia Post from the REST API.
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Result|bool
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
// Check if this method is active
if (!$this->getConfigFlag('active')) {
return false;
}
// Check if this method is even applicable (shipping from Australia)
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $request->getStore());
if ($origCountry != Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) {
return false;
}
if ($this->_client == null) {
return false;
}
$fromPostcode = (int) Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
$toPostcode = (int) $request->getDestPostcode();
$destCountry = $request->getDestCountryId();
if (!$destCountry) {
$destCountry = Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE;
}
/** @var Fontis_Australia_Helper_Australiapost $helper */
$helper = Mage::helper('australia/australiapost');
$weight = (int) $request->getPackageWeight();
$length = (int) $helper->getAttribute($request, 'length');
$width = (int) $helper->getAttribute($request, 'width');
$height = (int) $helper->getAttribute($request, 'height');
$extraCover = max((int) $request->getPackageValue(), self::EXTRA_COVER_LIMIT);
$config = array('from_postcode' => $fromPostcode, 'to_postcode' => $toPostcode, 'length' => $length, 'width' => $width, 'height' => $height, 'weight' => $weight, 'country_code' => $destCountry);
$this->_getQuotes($extraCover, $config);
$_result = $this->_result->asArray();
if (empty($_result)) {
return false;
}
return $this->_result;
}
示例4: _getCourierRate
protected function _getCourierRate(Mage_Shipping_Model_Rate_Request $request)
{
$package_cost = $request->getPackageValueWithDiscount();
$shipping_settings = Mage::helper('altteam_qwintry')->getShippingSettings();
$pounds = $request->getPackageWeight();
$currencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$currency = $request->getPackageCurrency();
if (in_array('USD', $currencies)) {
Mage::helper('directory')->currencyConvert($package_cost, $currency->getCurrencyCode(), 'USD');
} elseif ($currency->getCurrencyCode() == 'EUR') {
$package_cost = $package_cost * 1.097;
} elseif ($currency->getCurrencyCode() == 'RMB') {
$package_cost = $package_cost * 1.157;
}
$data = array('params' => array('method' => 'qwair', 'hub_code' => empty($shipping_settings['hub']) ? 'DE1' : $shipping_settings['hub'], 'insurance' => false, 'retail_pricing' => false, 'weight' => $pounds > 0.1 ? $pounds : (empty($shipping_settings['default_weight']) ? 4 : $shipping_settings['default_weight']), 'items_value' => $package_cost, 'addr_country' => $request->getDestCountryId(), 'addr_zip' => $request->getDestPostcode(), 'addr_line1' => $request->getDestStreet(), 'addr_line2' => '', 'addr_city' => $request->getDestCity(), 'addr_state' => $request->getDestRegionCode()));
$response = Mage::helper('altteam_qwintry')->sendApiRequest('cost', $data);
if (!$response || empty($response->success) || !$response->success) {
return false;
}
$rate = Mage::getModel('shipping/rate_result_method');
$rate->setCarrier($this->_code);
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod('courier');
$rate->setMethodTitle('Courier');
$rate->setPrice($response->result->total);
$rate->setCost(0);
return $rate;
}
示例5: getRate
public function getRate(Mage_Shipping_Model_Rate_Request $request)
{
$read = $this->_getReadAdapter();
$write = $this->_getWriteAdapter();
$select = $read->select()->from($this->getMainTable());
/*
//commented out code since we don't want to get state by using zip code
if (!$request->getDestCountryId() && !$request->getDestRegionId()) {
// assuming that request is coming from shopping cart
// for shipping prices pre-estimation...
// also probably it will be required to move this part to
// Sales/Model/Quote/Address.php !
$selectCountry = $read->select()->from(Mage::getSingleton('core/resource')->getTableName('usa/postcode'), array('country_id', 'region_id'));
$selectCountry->where('postcode=?', $request->getDestPostcode());
$selectCountry->limit(1);
$countryRegion = $read->fetchRow($selectCountry);
$region = $read->quote($countryRegion['region_id']);
$country = $read->quote($countryRegion['country_id']);
} else {
$region = $read->quote($request->getDestRegionId());
$country = $read->quote($request->getDestCountryId());
}
*/
$region = $read->quote($request->getDestRegionId());
$country = $read->quote($request->getDestCountryId());
$zip = $read->quote($request->getDestPostcode());
$select->where("(dest_zip={$zip})\n OR (dest_region_id={$region} AND dest_zip='')\n OR (dest_country_id={$country} AND dest_region_id='0' AND dest_zip='')\n OR (dest_country_id='0' AND dest_region_id='0' AND dest_zip='')");
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_value<=?', $request->getData($conditionName));
$i++;
}
} else {
$select->where('condition_name=?', $request->getConditionName());
$select->where('condition_value<=?', $request->getData($request->getConditionName()));
}
$select->where('website_id=?', $request->getWebsiteId());
$select->order('condition_value DESC')->limit(1);
$row = $read->fetchRow($select);
return $row;
}
示例6: setBaseRequest
public function setBaseRequest(Mage_Shipping_Model_Rate_Request $request)
{
$r = new Varien_Object();
$r->setAllowedMethods($this->getConfigData('allowed_methods'));
$r->setWeight(ceil($request->getPackageWeight() * (double) $this->getConfigData('wt_units')));
if ($request->getOrigPostcode()) {
$r->setOrigPostal($request->getOrigPostcode());
} else {
$r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()));
}
if ($request->getDestCountryId()) {
$destCountry = $request->getDestCountryId();
} else {
$destCountry = self::USA_COUNTRY_ID;
}
$r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code());
$r->setDestCountryIso3(Mage::getModel('directory/country')->load($destCountry)->getIso3Code());
$r->setDestCountryName(Mage::getModel('directory/country')->load($destCountry)->getName());
$r->setMailClass($this->getDeliveryServiceLevel($destCountry));
if ($request->getDestPostcode()) {
$r->setDestPostal('US' == $r->getDestCountry() ? substr($request->getDestPostcode(), 0, 5) : $request->getDestPostcode());
}
return $r;
}
示例7: getNewRate
public function getNewRate(Mage_Shipping_Model_Rate_Request $request, $zipRangeSet = 0)
{
$newdata = array();
$collection = Mage::getResourceModel('matrixrate_shipping/carrier_matrixrate_collection');
$collection->setConditionFilter($request->getConditionName())->setWebsiteFilter($request->getWebsiteId());
$collection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns(array('website_id', 'zone', 'condition_name', 'condition_from_value', 'condition_to_value', 'shipping_charge'));
$collection->getSelect()->join(array('zones' => 'shipping_zones'), "zones.zone=s.zone and zones.delivery_type='standard' and zones.country_code='" . $request->getDestCountryId() . "' AND (condition_from_value<='" . $request->getData($request->getConditionName()) . "') AND (condition_to_value>='" . $request->getData($request->getConditionName()) . "')", array('delivery_type', 'shipping_provider'));
//print $collection->getSelect();die;
if ($collection->count()) {
foreach ($collection->getData() as $data) {
$newdata[] = $data;
}
}
return $newdata;
}
示例8: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
return false;
}
$destinationData = array('city' => ucwords(strtolower($request->getDestCity())), 'country_id' => $request->getDestCountryId(), 'postcode' => $request->getDestPostcode());
$quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$quote = Mage::getModel("sales/quote")->load($quoteId);
$result = Mage::getModel('aramexshipping/shipping')->getRatesAndPackages($quote, true, $destinationData);
$error = $result['error'];
$error_msg = isset($result['error_msg']) ? 'Aramex Error: ' . $result['error_msg'] : '';
$price = $result['price'];
$methodTitle = $request->getFreeShipping() ? Mage::helper('aramexshipping')->__('Free shipping applied') : '';
$handling = Mage::getStoreConfig('carriers/' . $this->_code . '/handling');
$result = Mage::getModel('shipping/rate_result');
if (!$error && $price > 0 || !$error && $request->getFreeShipping()) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setMethod($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethodTitle($methodTitle);
$method->setPrice($price);
$method->setCost($price);
$result->append($method);
} else {
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title'));
$error->setErrorMessage($error_msg ? $error_msg : $this->getConfigData('specificerrmsg'));
$result->append($error);
if ($error_msg) {
Mage::helper('aramexshipping')->log($error_msg, '', 'aramex_collect_rates');
Mage::helper('aramexshipping')->sendLogEmail(array('subject' => 'Collect Rates Error Log', 'content' => $error_msg));
}
}
return $result;
}
示例9: getRate
/**
* Fetch rate from the table for selected shipping address.
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return array
*/
public function getRate(Mage_Shipping_Model_Rate_Request $request)
{
$adapter = $this->_getReadAdapter();
$bind = array(':website_id' => (int) $request->getWebsiteId(), ':country_id' => $request->getDestCountryId(), ':region_id' => (int) $request->getDestRegionId(), ':postcode' => $request->getDestPostcode());
$select = $adapter->select()->from($this->getMainTable())->where('website_id = :website_id')->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'condition_value DESC'))->limit(1);
// Render destination condition
$orWhere = '(' . implode(') OR (', array("dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode", "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''", "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = '*'", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'", "dest_country_id = '0' AND dest_region_id = :region_id AND dest_zip = '*'", "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'")) . ')';
$select->where($orWhere);
// Render condition by condition name
if (is_array($request->getConditionName())) {
$orWhere = array();
$i = 0;
foreach ($request->getConditionName() as $conditionName) {
$bindNameKey = sprintf(':condition_name_%d', $i);
$bindValueKey = sprintf(':condition_value_%d', $i);
$orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})";
$bind[$bindNameKey] = $conditionName;
$bind[$bindValueKey] = $request->getData($conditionName);
$i++;
}
if ($orWhere) {
$select->where(implode(' OR ', $orWhere));
}
} else {
$bind[':condition_name'] = $request->getConditionName();
$bind[':condition_value'] = $request->getData($request->getConditionName());
$select->where('condition_name = :condition_name');
$select->where('condition_value <= :condition_value');
}
$result = $adapter->fetchRow($select, $bind);
// Normalize destination zip code
if ($result && $result['dest_zip'] == '*') {
$result['dest_zip'] = '';
}
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: getRate
/**
* Return table rate array or false by rate request
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return array|false
*/
public function getRate(Mage_Shipping_Model_Rate_Request $request)
{
$adapter = $this->_getReadAdapter();
$bind = array(':website_id' => (int) $request->getWebsiteId(), ':country_id' => $request->getDestCountryId(), ':region_id' => $request->getDestRegionId());
$select = $adapter->select()->from($this->getMainTable())->where('website_id=:website_id')->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC'))->limit(1);
// render destination condition
$orWhere = '(' . implode(') OR (', array("dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip like '{$request->getDestPostcode()}%'", "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip like '{$request->getDestPostcode()}%'", "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = ''")) . ')';
$select->where($orWhere);
// render condition by condition name
if (is_array($request->getConditionName())) {
$orWhere = array();
$i = 0;
foreach ($request->getConditionName() as $conditionName) {
$bindNameKey = sprintf(':condition_name_%d', $i);
$bindValueKey = sprintf(':condition_value_%d', $i);
$orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})";
$bind[$bindNameKey] = $conditionName;
$bind[$bindValueKey] = $request->getData($conditionName);
$i++;
}
if ($orWhere) {
$select->where(implode(' OR ', $orWhere));
}
} else {
$bind[':condition_name'] = $request->getConditionName();
$bind[':condition_value'] = $request->getData($request->getConditionName());
$select->where('condition_name = :condition_name');
$select->where('condition_value <= :condition_value');
}
//if( $_SERVER['REMOTE_ADDR'] == '193.108.122.187') { mage::D($bind ); mage::d($select->__toString()); }
return $adapter->fetchRow($select, $bind);
}
示例12: _getProductionShipmentFields
private function _getProductionShipmentFields(Mage_Shipping_Model_Rate_Request $mgrequest)
{
$regionId = $mgrequest->getRegionId();
$region = Mage::getModel('directory/region')->load($regionId);
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
//$request->Shipment->SenderInformation->Address->StreetNumber = "1234";
$request->Shipment->SenderInformation->Address->StreetName = $mgrequest->getStreet();
$request->Shipment->SenderInformation->Address->City = $mgrequest->getCity();
$request->Shipment->SenderInformation->Address->Province = $region->getCode();
$request->Shipment->SenderInformation->Address->Country = $mgrequest->getCountryId();
$request->Shipment->SenderInformation->Address->PostalCode = $mgrequest->getPostcode();
$request->Shipment->SenderInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->SenderInformation->Address->PhoneNumber->AreaCode = "905";
$request->Shipment->SenderInformation->Address->PhoneNumber->Phone = substr("123456789", -7);
//Populate the Desination Information
$request->Shipment->ReceiverInformation->Address->Name = "Aaron Summer";
$request->Shipment->ReceiverInformation->Address->StreetName = $mgrequest->getDestStreet();
$request->Shipment->ReceiverInformation->Address->City = $mgrequest->getDestCity();
$regionId = $mgrequest->getDestRegionId();
$region = Mage::getModel('directory/region')->load($regionId);
$request->Shipment->ReceiverInformation->Address->Province = $region->getCode();
$request->Shipment->ReceiverInformation->Address->Country = $mgrequest->getDestCountryId();
$request->Shipment->ReceiverInformation->Address->PostalCode = $mgrequest->getDestPostcode();
$request->Shipment->ReceiverInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->AreaCode = "604";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->Phone = substr("123456789", -7);
//Future Dated Shipments - YYYY-MM-DD format
$request->Shipment->ShipmentDate = Mage::getModel('core/date')->date('Y-m-d');
//Populate the Package Information
$request->Shipment->PackageInformation->TotalWeight->Value = $mgrequest->getPackageWeight();
$request->Shipment->PackageInformation->TotalWeight->WeightUnit = "lb";
$request->Shipment->PackageInformation->TotalPieces = $mgrequest->getPackageQty();
$request->Shipment->PackageInformation->ServiceID = "PurolatorExpress";
//Populate the Payment Information
$request->Shipment->PaymentInformation->PaymentType = "Sender";
$request->Shipment->PaymentInformation->BillingAccountNumber = $this->BILLING_ACCOUNT;
$request->Shipment->PaymentInformation->RegisteredAccountNumber = $this->REGISTERED_ACCOUNT;
//Populate the Pickup Information
$request->Shipment->PickupInformation->PickupType = "DropOff";
$request->ShowAlternativeServicesIndicator = "true";
//OriginSignatureNotRequired
$request->Shipment->PackageInformation->OptionsInformation->Options->OptionIDValuePair->ID = "OriginSignatureNotRequired";
$request->Shipment->PackageInformation->OptionsInformation->Options->OptionIDValuePair->Value = "true";
return $request;
}
示例13: getNewRate
public function getNewRate(Mage_Shipping_Model_Rate_Request $request, $zipRangeSet = 0)
{
$read = $this->_getReadAdapter();
$write = $this->_getWriteAdapter();
$postcode = $request->getDestPostcode();
$table = Mage::getSingleton('core/resource')->getTableName('matrixrate_shipping/matrixrate');
if ($zipRangeSet && is_numeric($postcode)) {
# Want to search for postcodes within a range
$zipSearchString = ' AND ' . $postcode . ' BETWEEN dest_zip AND dest_zip_to )';
} else {
$zipSearchString = $read->quoteInto(" AND ? LIKE dest_zip )", $postcode);
}
for ($j = 0; $j < 10; $j++) {
$select = $read->select()->from($table);
switch ($j) {
case 0:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? ", $request->getDestRegionId()) . $read->quoteInto(" AND STRCMP(LOWER(dest_city),LOWER(?)) = 0 ", $request->getDestCity()) . $zipSearchString);
break;
case 1:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? AND dest_city=''", $request->getDestRegionId()) . $zipSearchString);
break;
case 2:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? ", $request->getDestRegionId()) . $read->quoteInto(" AND STRCMP(LOWER(dest_city),LOWER(?)) = 0 AND dest_zip='')", $request->getDestCity()));
break;
case 3:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND STRCMP(LOWER(dest_city),LOWER(?)) = 0 AND dest_region_id='0'", $request->getDestCity()) . $zipSearchString);
break;
case 4:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND STRCMP(LOWER(dest_city),LOWER(?)) = 0 AND dest_region_id='0' AND dest_zip='') ", $request->getDestCity()));
break;
case 5:
$select->where($read->quoteInto(" (dest_country_id=? AND dest_region_id='0' AND dest_city='' ", $request->getDestCountryId()) . $zipSearchString);
break;
case 6:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? AND dest_city='' AND dest_zip='') ", $request->getDestRegionId()));
break;
case 7:
$select->where($read->quoteInto(" (dest_country_id=? AND dest_region_id='0' AND dest_city='' AND dest_zip='') ", $request->getDestCountryId()));
break;
case 8:
$select->where(" (dest_country_id='0' AND dest_region_id='0'" . $zipSearchString);
break;
case 9:
$select->where(" (dest_country_id='0' AND dest_region_id='0' AND dest_zip='')");
break;
}
if (is_array($request->getMRConditionName())) {
$i = 0;
foreach ($request->getMRConditionName() as $conditionName) {
if ($i == 0) {
$select->where('condition_name=?', $conditionName);
} else {
$select->orWhere('condition_name=?', $conditionName);
}
$select->where('condition_from_value<=?', $request->getData($conditionName));
$i++;
}
} else {
$select->where('condition_name=?', $request->getMRConditionName());
$select->where('condition_from_value<=?', $request->getData($request->getMRConditionName()));
$select->where('condition_to_value>=?', $request->getData($request->getMRConditionName()));
}
$select->where('website_id=?', $request->getWebsiteId());
if ($filter = $request->getData('filter')) {
$select->where('filter IN (?)', $filter);
}
$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)) {
// have found a result or found nothing and at end of list!
foreach ($row as $data) {
$newdata[] = $data;
}
break;
}
}
return $newdata;
}
示例14: getMethods
/**
* Collect rates for this shipping method based on information in $request
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function getMethods(Mage_Shipping_Model_Rate_Request $request, $my_code = false)
{
$dest_country = $request->getDestCountryId();
$dest_region = $request->getDestRegionId();
$package_value = $request->getPackageValue();
$shipping_price = 0;
// Mage::log($request->debug(), null, 'test.log');
// Mage::log($exception_regions, null, 'test.log');
// Mage::log($dest_country, null, 'test.log');
// Mage::log($dest_region, null, 'test.log');
$i = 1;
$max_price = 0;
$items = array();
$cart_products_price_reduction = 0;
if ($_items = $request->getAllItems()) {
foreach ($_items as $item) {
// if($item->getProductType() != 'simple') continue;
// Mage::log($i++, null, 'test.log');
// Mage::log($item->debug(), null, 'test.log');
if ($parent_item_id = $item->getParentItemId()) {
continue;
// $items[$item_id]['free_shipping'] = $item->getMaxFreeShipping();
// $items[$item_id]['primary_shipping'] = $item->getMaxPrimaryShip();
// $items[$item_id]['secondary_shipping'] = $item->getMaxSecondaryShip();
} elseif ($item->getProductType() == 'cartproduct') {
continue;
}
$p = Mage::getModel('catalog/product')->load($item->getProductId());
$item_id = $item->getItemId();
$items[$item_id]['price'] = $item->getPrice();
$items[$item_id]['sku'] = $item->getSku();
$items[$item_id]['qty'] = $item->getQty();
$items[$item_id]['free_shipping'] = $p->getMaxFreeShipping();
$items[$item_id]['primary_shipping'] = $p->getMaxPrimaryShip();
$items[$item_id]['secondary_shipping'] = $p->getMaxSecondaryShip();
if ($item->getPrice() >= $max_price) {
$max_price = $item->getPrice();
$max_id = $item_id;
}
// $p = Mage::getModel('catalog/product')->load($item->getProductId());
// $tmp_price = (float) $p->getFreightShipTotal();
// Mage::log($p->getData(), null, 'test.log');
// Mage::log($item->debug(), null, 'test.log');
}
}
foreach ($items as $item_id => $item) {
$qty = (int) $item['qty'];
$max_done = false;
for ($i = 1; $i <= $qty; $i++) {
if (!$max_done && $item_id == $max_id) {
$shipping_price += $item['free_shipping'] ? 0 : (double) $item['primary_shipping'];
$max_done = true;
continue;
}
$shipping_price += $item['free_shipping'] ? 0 : (double) $item['secondary_shipping'];
}
}
// 199.5 + 105 + 210
if ($dest_country == 'CA') {
$item_percent = (double) Mage::getStoreConfig('carriers/maxshipping/canadian_percent') / 100;
$duty = (double) Mage::getStoreConfig('carriers/maxshipping/canadian_duty') / 100;
$tax = (double) Mage::getStoreConfig('carriers/maxshipping/canadian_tax') / 100;
$shipping_price += $request->getPackagePhysicalValue() * $item_percent;
$shipping_price += $request->getPackagePhysicalValue() * $duty;
$shipping_price += $request->getPackagePhysicalValue() * $tax;
$shipping_price += (double) Mage::getStoreConfig('carriers/maxshipping/canadian_border_fee');
}
$methods = array();
// $label = Mage::getStoreConfig('carriers/maxshipping/title');
$method = Mage::getModel('shipping/rate_result_method');
$method->setMethodTitle('');
$method->setCarrier($this->_code);
$method->setMethod('standard');
$method->setPrice($shipping_price);
$methods[] = $method;
// Mage::log($methods, null, 'methods.log');
return $methods;
}
示例15: _submitRequest
/**
* @param Mage_Shipping_Model_Rate_Request $requestVar
* @return array
*/
private function _submitRequest(Mage_Shipping_Model_Rate_Request $requestVar)
{
$shipwireAvailableServices = $this->getConfigData('availableservices');
$shipwireUsername = $this->getConfigData('shipwire_email');
$shipwirePassword = $this->getConfigData('shipwire_password');
$orderCurrencyCode = 'USD';
/**
* @var $orderCurrency Mage_Directory_Model_Currency
*/
$orderCurrency = $requestVar->getBaseCurrency();
if (!empty($orderCurrency)) {
$orderCurrencyCode = $orderCurrency->getCode();
}
$orderNumber = uniqid('magento', TRUE);
$shipToAddress1 = $requestVar->getDestStreet();
$shipToCity = $requestVar->getDestCity();
$shipToRegion = $requestVar->getDestRegionCode();
$shipToCountry = $requestVar->getDestCountryId();
$shiptoPostalCode = $requestVar->getDestPostcode();
$requestItems = $requestVar->getAllItems();
$itemXml = $this->_buildRequestItemXml($requestItems);
$rateRequestXml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE RateRequest SYSTEM "http://www.shipwire.com/exec/download/RateRequest.dtd">
<RateRequest currency="{$orderCurrencyCode}">
<Username><![CDATA[{$shipwireUsername}]]></Username>
<Password><![CDATA[{$shipwirePassword}]]></Password>
<Source>{$this->_version}</Source>
<Order id="{$orderNumber}">
<AddressInfo type="ship">
<Address1><![CDATA[{$shipToAddress1}]]></Address1>
<City><![CDATA[{$shipToCity}]]></City>
<State><![CDATA[{$shipToRegion}]]></State>
<Country><![CDATA[{$shipToCountry}]]></Country>
<Zip><![CDATA[{$shiptoPostalCode}]]></Zip>
</AddressInfo>
{$itemXml}
</Order>
</RateRequest>
XML;
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $this->_apiEndpoint);
curl_setopt($curlSession, CURLOPT_POST, true);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $rateRequestXml);
curl_setopt($curlSession, CURLOPT_HEADER, false);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlSession, CURLOPT_TIMEOUT, 60);
$response = curl_exec($curlSession);
$emptyRateResult = array();
if (FALSE === $response) {
return $emptyRateResult;
}
$parser = xml_parser_create();
xml_parse_into_struct($parser, $response, $xmlVals, $xmlIndex);
xml_parser_free($parser);
foreach ($xmlVals as $key) {
if ($key['tag'] == 'STATUS') {
if ($key['value'] != 'OK') {
return $emptyRateResult;
}
}
}
$code = array();
$method = array();
$cost = array();
$supportedServices = explode(',', $shipwireAvailableServices);
foreach ($xmlVals as $key) {
if ($key['tag'] == 'QUOTE' && $key['type'] == 'open' && $key['level'] == 4) {
$code[] = $key['attributes']['METHOD'];
}
if ($key['tag'] == 'SERVICE' && $key['type'] == 'complete' && $key['level'] == 5) {
$method[] = $key['value'];
}
if ($key['tag'] == 'COST' && $key['type'] == 'complete' && $key['level'] == 5) {
$cost[] = $key['value'];
}
}
$la = count($code);
$lb = count($method);
$lc = count($cost);
$rateResult = array();
if ($la == $lb && $lb == $lc) {
foreach ($code as $index => $value) {
if (in_array($value, $supportedServices)) {
$rateResult[] = array('code' => $code[$index], 'title' => $method[$index], 'amount' => $cost[$index]);
}
}
}
return $rateResult;
}