本文整理汇总了PHP中Mage_Shipping_Model_Rate_Request类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Shipping_Model_Rate_Request类的具体用法?PHP Mage_Shipping_Model_Rate_Request怎么用?PHP Mage_Shipping_Model_Rate_Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Shipping_Model_Rate_Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: proccessAdditionalValidation
/**
* Processing additional validation to check is carrier applicable.
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
*/
public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
{
//Skip by item validation if there is no items in request
if (!count($request->getAllItems())) {
return $this;
}
$maxAllowedWeight = (double) $this->getConfigData('max_package_weight');
$error = null;
$showMethod = $this->getConfigData('showmethod');
foreach ($request->getAllItems() as $item) {
if ($item->getProduct() && $item->getProduct()->getId()) {
if ($item->getProduct()->getWeight() > $maxAllowedWeight) {
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code)->setCarrierTitle($this->getConfigData('title'));
$errorMsg = $this->getConfigData('specificerrmsg');
$error->setErrorMessage($errorMsg ? $errorMsg : Mage::helper('shipping')->__('The shipping module is not available.'));
break;
}
}
}
if (null !== $error && $showMethod) {
return $error;
} elseif (null !== $error) {
return false;
}
return $this;
}
示例2: collectRates
/**
* Retrieve all methods for supplied shipping data
*
* @todo make it ordered
* @param Mage_Shipping_Model_Shipping_Method_Request $data
* @return Mage_Shipping_Model_Shipping
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$storeId = $request->getStoreId();
if (!$request->getOrig()) {
$request->setCountryId(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_COUNTRY_ID, $storeId))->setRegionId(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_REGION_ID, $storeId))->setCity(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_CITY, $storeId))->setPostcode(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_POSTCODE, $storeId));
}
$limitCarrier = $request->getLimitCarrier();
if (!$limitCarrier) {
$carriers = Mage::getStoreConfig('carriers', $storeId);
foreach ($carriers as $carrierCode => $carrierConfig) {
$this->collectCarrierRates($carrierCode, $request);
}
} else {
if (!is_array($limitCarrier)) {
$limitCarrier = array($limitCarrier);
}
foreach ($limitCarrier as $carrierCode) {
$carrierConfig = Mage::getStoreConfig('carriers/' . $carrierCode, $storeId);
if (!$carrierConfig) {
continue;
}
$this->collectCarrierRates($carrierCode, $request);
}
}
return $this;
}
示例3: collectRates
/**
* FreeShipping Rates Collector
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$ischeck = Mage::getStoreConfig('giftwrap/general/add_product_price');
if ($ischeck) {
$giftwrapAmount = Mage::helper('giftwrap')->giftwrapAmount();
} else {
$giftwrapAmount = 0;
}
if (!$this->getConfigFlag('active')) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
// $packageValue = $request->getBaseCurrency()->convert($request->getPackageValueWithDiscount(), $request->getPackageCurrency());
$packageValue = $request->getPackageValueWithDiscount();
$this->_updateFreeMethodQuote($request);
$allow = $request->getFreeShipping() || $packageValue + $giftwrapAmount >= $this->getConfigData('free_shipping_subtotal');
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;
}
示例4: collectRates
/**
* Retrieve all methods for supplied shipping data
*
* @todo make it ordered
* @param Mage_Shipping_Model_Shipping_Method_Request $data
* @return Mage_Shipping_Model_Shipping
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$request->getOrig()) {
$request->setCountryId(Mage::getStoreConfig('shipping/origin/country_id', $request->getStore()))->setRegionId(Mage::getStoreConfig('shipping/origin/region_id', $request->getStore()))->setCity(Mage::getStoreConfig('shipping/origin/city', $request->getStore()))->setPostcode(Mage::getStoreConfig('shipping/origin/postcode', $request->getStore()));
}
$limitCarrier = $request->getLimitCarrier();
if (!$limitCarrier) {
$carriers = Mage::getStoreConfig('carriers', $request->getStoreId());
foreach ($carriers as $carrierCode => $carrierConfig) {
$this->collectCarrierRates($carrierCode, $request);
}
} else {
if (!is_array($limitCarrier)) {
$limitCarrier = array($limitCarrier);
}
foreach ($limitCarrier as $carrierCode) {
$carrierConfig = Mage::getStoreConfig('carriers/' . $carrierCode, $request->getStoreId());
if (!$carrierConfig) {
continue;
}
$this->collectCarrierRates($carrierCode, $request);
}
}
return $this;
}
示例5: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$result = Mage::getModel('shipping/rate_result');
/* @var $result Mage_Shipping_Model_Rate_Result */
$result->append($this->_getStandardShippingRate());
$expressWeightThreshold = $this->getConfigData('express_weight_threshold');
$eligibleForExpressDelivery = true;
foreach ($request->getAllItems() as $_item) {
if ($_item->getWeight() > $expressWeightThreshold) {
$eligibleForExpressDelivery = false;
}
}
if ($eligibleForExpressDelivery) {
$result->append($this->_getExpressShippingRate());
}
if ($request->getFreeShipping()) {
/**
* If the request has the free shipping flag,
* append a free shipping rate to the result.
*/
$freeShippingRate = $this->_getFreeShippingRate();
$result->append($freeShippingRate);
}
return $result;
}
示例6: 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');
if ($this->getConfigData('type') == 'O') {
// per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price');
} else {
$shippingPrice = false;
}
$shippingPrice += $this->getConfigData('handling_fee');
if ($shippingPrice) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('flatrate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrate');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
示例7: 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;
}
示例8: collectRates
/**
* 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 collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigData('active')) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
$collection = Mage::getResourceModel('amtable/method_collection')->addFieldToFilter('is_active', 1)->addStoreFilter($request->getStoreId())->addCustomerGroupFilter($this->getCustomerGroupId($request))->setOrder('pos');
$rates = Mage::getModel('amtable/rate')->findBy($request, $collection);
foreach ($collection as $customMethod) {
// create new instance of method rate
$method = Mage::getModel('shipping/rate_result_method');
// record carrier information
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
// record method information
$method->setMethod($this->_code . $customMethod->getId());
$method->setMethodTitle(Mage::helper('amtable')->__($customMethod->getName()));
if (isset($rates[$customMethod->getId()])) {
$method->setCost($rates[$customMethod->getId()]);
$method->setPrice($rates[$customMethod->getId()]);
// add this rate to the result
$result->append($method);
}
}
return $result;
}
示例9: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$shippingPrice = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'bundle') {
continue;
}
$shipCost = $product->getShipCost();
if ($shipCost == null || $shipCost == 0) {
$shippingPrice += $item->getQty() * $this->getConfigData('price');
} else {
$shippingPrice += $item->getQty() * $shipCost;
}
}
}
$result = Mage::getModel('shipping/rate_result');
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('flatrateperproduct');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrateperproduct');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
示例10: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
$rawPostcode = $request->getDestPostcode();
$postCode = Mage::helper('freight')->validatePostcode($rawPostcode);
if (empty($postCode)) {
return $result;
}
$packageWeight = $request->getPackageWeight();
$shipping = Mage::getModel('freight/config')->getShippingPrice($this->_code, $postCode, $packageWeight);
if ($shipping != null) {
$shippingDeliveryPrice = $shipping->getData('delivery_price') / 100;
$shippingDeliveryTime = $shipping->getData('delivery_time');
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($this->_code);
$method->setMethodTitle($this->getConfigData('name') . Mage::helper('freight')->formatShippingTime($shippingDeliveryTime));
$method->setPrice($shippingDeliveryPrice);
$method->setCost($shippingDeliveryPrice);
$result->append($method);
}
return $result;
}
示例11: 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;
}
示例12: collectRates
/**
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
/** @var Mage_Shipping_Model_Rate_Result $result */
$result = Mage::getModel('shipping/rate_result');
$totalWeight = 0;
foreach ($request->getAllItems() as $item) {
$totalWeight += $item->getWeight() * $item->getQty();
}
/** @var string $hostname */
$hostname = $this->getConfigData('hostname');
/** @var string $port */
$port = $this->getConfigData('port');
try {
$client = new Zend_Http_Client();
$response = $client->setUri("http://{$hostname}:{$port}/")->setRawData(json_encode(['totalWeight' => $totalWeight]))->setEncType('application/json')->request('POST');
switch ($response->getStatus()) {
case 200:
$responseBody = json_decode($response->getBody());
$result->append($this->_getShippingMethod($responseBody->rate));
break;
case 500:
// Handle 500 Error
break;
default:
}
} catch (Exception $e) {
var_dump($e);
}
return $result;
}
示例13: proccessAdditionalValidation
/**
* Processing additional validation to check is carrier applicable.
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
*/
public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
{
//Skip by item validation if there is no items in request
if (!count($request->getAllItems())) {
return $this;
}
$maxAllowedWeight = (double) $this->getConfigData('max_package_weight');
$errorMsg = '';
$configErrorMsg = $this->getConfigData('specificerrmsg');
$defaultErrorMsg = Mage::helper('shipping')->__('The shipping module is not available.');
$showMethod = $this->getConfigData('showmethod');
foreach ($request->getAllItems() as $item) {
if ($item->getProduct() && $item->getProduct()->getId()) {
if ($item->getProduct()->getWeight() > $maxAllowedWeight) {
$errorMsg = $configErrorMsg ? $configErrorMsg : $defaultErrorMsg;
break;
}
}
}
if (!$errorMsg && !$request->getDestPostcode() && $this->isZipCodeRequired()) {
$errorMsg = Mage::helper('shipping')->__('This shipping method is not available, please specify ZIP-code');
}
if ($errorMsg && $showMethod) {
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title'));
$error->setErrorMessage($errorMsg);
return $error;
} elseif ($errorMsg) {
return false;
}
return $this;
}
示例14: setRequest
/**
* Prepare and set request to this instance
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Usa_Model_Shipping_Carrier_Ups
*/
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$quote = $request->getQuote();
if (!$quote || !$quote->getId()) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
}
if (!$quote || !$quote->getId() && Mage::registry('recurring_order', false)) {
$quote = Mage::registry('recurring_order')->getQuote();
}
if ($quote && $quote->getId()) {
Mage::unregister('recurring_quote');
Mage::register('recurring_quote', $quote);
}
parent::setRequest($request);
if (!$quote || !$quote->getId()) {
return $this;
}
// last attempt at checking this damn thing
if (!$quote->getShippingAddress()->getResidentialIndicator()) {
Mage::dispatchEvent('widgetized_validate_address', array($this->_eventObject => $this, 'order' => $quote));
}
// Manually overriding the residential indicator
if ($indicator = $quote->getShippingAddress()->getResidentialIndicator()) {
$this->_rawRequest->setDestType($indicator);
}
return $this;
}
示例15: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$result = Mage::getModel('shipping/rate_result');
foreach ($request->getAllItems() as $item) {
}
$result->append($this->_getStandardRate());
return $result;
}