本文整理匯總了PHP中Magento\Quote\Model\Quote\Address::getBaseShippingAmount方法的典型用法代碼示例。如果您正苦於以下問題:PHP Address::getBaseShippingAmount方法的具體用法?PHP Address::getBaseShippingAmount怎麽用?PHP Address::getBaseShippingAmount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Quote\Model\Quote\Address
的用法示例。
在下文中一共展示了Address::getBaseShippingAmount方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getBaseShippingAmount
/**
* {@inheritdoc}
*/
public function getBaseShippingAmount()
{
return $this->_address->getBaseShippingAmount();
}
示例2: processShippingAmount
/**
* Apply discounts to shipping amount
*
* @param Address $address
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function processShippingAmount(Address $address)
{
$shippingAmount = $address->getShippingAmountForDiscount();
if ($shippingAmount !== null) {
$baseShippingAmount = $address->getBaseShippingAmountForDiscount();
} else {
$shippingAmount = $address->getShippingAmount();
$baseShippingAmount = $address->getBaseShippingAmount();
}
$quote = $address->getQuote();
$appliedRuleIds = [];
foreach ($this->_getRules() as $rule) {
/* @var \Magento\SalesRule\Model\Rule $rule */
if (!$rule->getApplyToShipping() || !$this->validatorUtility->canProcessRule($rule, $address)) {
continue;
}
$discountAmount = 0;
$baseDiscountAmount = 0;
$rulePercent = min(100, $rule->getDiscountAmount());
switch ($rule->getSimpleAction()) {
case \Magento\SalesRule\Model\Rule::TO_PERCENT_ACTION:
$rulePercent = max(0, 100 - $rule->getDiscountAmount());
// break is intentionally omitted
// break is intentionally omitted
case \Magento\SalesRule\Model\Rule::BY_PERCENT_ACTION:
$discountAmount = ($shippingAmount - $address->getShippingDiscountAmount()) * $rulePercent / 100;
$baseDiscountAmount = ($baseShippingAmount - $address->getBaseShippingDiscountAmount()) * $rulePercent / 100;
$discountPercent = min(100, $address->getShippingDiscountPercent() + $rulePercent);
$address->setShippingDiscountPercent($discountPercent);
break;
case \Magento\SalesRule\Model\Rule::TO_FIXED_ACTION:
$quoteAmount = $this->priceCurrency->convert($rule->getDiscountAmount(), $quote->getStore());
$discountAmount = $shippingAmount - $quoteAmount;
$baseDiscountAmount = $baseShippingAmount - $rule->getDiscountAmount();
break;
case \Magento\SalesRule\Model\Rule::BY_FIXED_ACTION:
$quoteAmount = $this->priceCurrency->convert($rule->getDiscountAmount(), $quote->getStore());
$discountAmount = $quoteAmount;
$baseDiscountAmount = $rule->getDiscountAmount();
break;
case \Magento\SalesRule\Model\Rule::CART_FIXED_ACTION:
$cartRules = $address->getCartFixedRules();
if (!isset($cartRules[$rule->getId()])) {
$cartRules[$rule->getId()] = $rule->getDiscountAmount();
}
if ($cartRules[$rule->getId()] > 0) {
$quoteAmount = $this->priceCurrency->convert($cartRules[$rule->getId()], $quote->getStore());
$discountAmount = min($shippingAmount - $address->getShippingDiscountAmount(), $quoteAmount);
$baseDiscountAmount = min($baseShippingAmount - $address->getBaseShippingDiscountAmount(), $cartRules[$rule->getId()]);
$cartRules[$rule->getId()] -= $baseDiscountAmount;
}
$address->setCartFixedRules($cartRules);
break;
}
$discountAmount = min($address->getShippingDiscountAmount() + $discountAmount, $shippingAmount);
$baseDiscountAmount = min($address->getBaseShippingDiscountAmount() + $baseDiscountAmount, $baseShippingAmount);
$address->setShippingDiscountAmount($discountAmount);
$address->setBaseShippingDiscountAmount($baseDiscountAmount);
$appliedRuleIds[$rule->getRuleId()] = $rule->getRuleId();
$this->rulesApplier->maintainAddressCouponCode($address, $rule, $this->getCouponCode());
$this->rulesApplier->addDiscountDescription($address, $rule);
if ($rule->getStopRulesProcessing()) {
break;
}
}
$address->setAppliedRuleIds($this->validatorUtility->mergeIds($address->getAppliedRuleIds(), $appliedRuleIds));
$quote->setAppliedRuleIds($this->validatorUtility->mergeIds($quote->getAppliedRuleIds(), $appliedRuleIds));
return $this;
}
示例3: getShippingDataObject
/**
* @param QuoteAddress $address
* @param bool $useBaseCurrency
* @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface
*/
public function getShippingDataObject(QuoteAddress $address, $useBaseCurrency)
{
if ($address->getShippingTaxCalculationAmount() === null) {
//Save the original shipping amount because shipping amount will be overridden
//with shipping amount excluding tax
$address->setShippingTaxCalculationAmount($address->getShippingAmount());
$address->setBaseShippingTaxCalculationAmount($address->getBaseShippingAmount());
}
if ($address->getShippingTaxCalculationAmount() !== null) {
/** @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface $itemDataObject */
$itemDataObject = $this->quoteDetailsItemDataObjectFactory->create()->setType(self::ITEM_TYPE_SHIPPING)->setCode(self::ITEM_CODE_SHIPPING)->setQuantity(1);
if ($useBaseCurrency) {
$itemDataObject->setUnitPrice($address->getBaseShippingTaxCalculationAmount());
} else {
$itemDataObject->setUnitPrice($address->getShippingTaxCalculationAmount());
}
if ($address->getShippingDiscountAmount()) {
if ($useBaseCurrency) {
$itemDataObject->setDiscountAmount($address->getBaseShippingDiscountAmount());
} else {
$itemDataObject->setDiscountAmount($address->getShippingDiscountAmount());
}
}
$itemDataObject->setTaxClassKey($this->taxClassKeyDataObjectFactory->create()->setType(TaxClassKeyInterface::TYPE_ID)->setValue($this->_config->getShippingTaxClass($address->getQuote()->getStore())));
$itemDataObject->setIsTaxIncluded($this->_config->shippingPriceIncludesTax($address->getQuote()->getStore()));
return $itemDataObject;
}
return null;
}