本文整理汇总了PHP中Magento\Quote\Model\Quote::getShippingAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP Quote::getShippingAddress方法的具体用法?PHP Quote::getShippingAddress怎么用?PHP Quote::getShippingAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\Quote
的用法示例。
在下文中一共展示了Quote::getShippingAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProductTaxRate
private function getProductTaxRate()
{
/** @var $taxCalculator \Magento\Tax\Model\Calculation */
$taxCalculator = $this->calculation;
$request = $taxCalculator->getRateRequest($this->quote->getShippingAddress(), $this->quote->getBillingAddress(), $this->quote->getCustomerTaxClassId(), $this->quote->getStore());
$request->setProductClassId($this->getProduct()->getTaxClassId());
return $taxCalculator->getRate($request);
}
示例2: getCountry
/**
* Get payment country
*
* @param Quote $quote
* @return int
*/
public function getCountry(Quote $quote)
{
$address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
return $address ? $address->getCountry() : $this->directoryHelper->getDefaultCountry();
}
示例3: _populateQuoteShippingMethod
public function _populateQuoteShippingMethod(\Magento\Quote\Model\Quote $quote)
{
/** @var \Magento\Quote\Model\Quote\Address $addr */
$addr = $quote->getShippingAddress();
$addr->setShippingMethod(self::METHOD_SHIPPING);
$addr->setCollectShippingRates(true);
$addr->collectShippingRates();
}
示例4: _beforeToHtml
/**
* Retrieve payment method and assign additional template values
*
* @return $this
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
protected function _beforeToHtml()
{
$methodInstance = $this->_quote->getPayment()->getMethodInstance();
$this->setPaymentMethodTitle($methodInstance->getTitle());
$this->setShippingRateRequired(true);
if ($this->_quote->getIsVirtual()) {
$this->setShippingRateRequired(false);
} else {
// prepare shipping rates
$this->_address = $this->_quote->getShippingAddress();
$groups = $this->_address->getGroupedAllShippingRates();
if ($groups && $this->_address) {
$this->setShippingRateGroups($groups);
// determine current selected code & name
foreach ($groups as $code => $rates) {
foreach ($rates as $rate) {
if ($this->_address->getShippingMethod() == $rate->getCode()) {
$this->_currentShippingRate = $rate;
break 2;
}
}
}
}
$canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()->getAdditionalInformation(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_BUTTON) == 1;
// misc shipping parameters
$this->setShippingMethodSubmitUrl($this->getUrl("{$this->_controllerPath}/saveShippingMethod"))->setCanEditShippingAddress($canEditShippingAddress)->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod());
}
$this->setEditUrl($this->getUrl("{$this->_controllerPath}/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_controllerPath}/placeOrder"));
return parent::_beforeToHtml();
}
示例5: populateQuoteAddress
/**
* @param \Magento\Quote\Model\Quote $quote
* @param array $details
* @return $this
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function populateQuoteAddress($quote, $details)
{
// import shipping address
$exportedShippingAddress = isset($details['shippingAddress']) ? $details['shippingAddress'] : null;
if (!$quote->getIsVirtual()) {
$shippingAddress = $quote->getShippingAddress();
if ($exportedShippingAddress) {
$this->importAddressData($shippingAddress, $exportedShippingAddress);
}
// PayPal doesn't provide detailed shipping info: prefix, suffix
$shippingAddress->setLastname($details['lastName']);
$shippingAddress->setFirstname($details['firstName']);
$shippingAddress->setEmail($details['email']);
$shippingAddress->setCollectShippingRates(true);
}
$exportedBillingAddress = isset($details['billingAddress']) ? $details['billingAddress'] : null;
$billingAddress = $quote->getBillingAddress();
if ($exportedBillingAddress) {
$this->importBillingAddressData($billingAddress, $exportedBillingAddress);
$billingAddress->setFirstname($details['firstName']);
$billingAddress->setLastname($details['lastName']);
$billingAddress->setEmail($details['email']);
} elseif ($billingAddress->getEmail() == null) {
$this->importAddressData($billingAddress, $exportedShippingAddress);
$billingAddress->setFirstname($details['firstName']);
$billingAddress->setLastname($details['lastName']);
$billingAddress->setEmail($details['email']);
}
return $this;
}
示例6: testSetMethod
/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
*/
public function testSetMethod()
{
$this->quote->load('test_order_1', 'reserved_order_id');
$serviceInfo = $this->getServiceInfo();
$cartId = $this->quote->getId();
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\QuoteIdMaskFactory')->create();
$quoteIdMask->load($cartId, 'quote_id');
//Use masked cart Id
$cartId = $quoteIdMask->getMaskedId();
$shippingAddress = $this->quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true);
$shippingAddress->collectTotals()->save();
$requestData = ['cartId' => $cartId, 'carrierCode' => 'flatrate', 'methodCode' => 'flatrate'];
$result = $this->_webApiCall($serviceInfo, $requestData);
$this->assertEquals(true, $result);
}
示例7: populateCustomerInfo
/**
* Populate customer model
*
* @param Quote $quote
* @return void
*/
public function populateCustomerInfo(QuoteEntity $quote)
{
$customer = $quote->getCustomer();
if (!$customer->getId()) {
$customer = $this->accountManagement->createAccountWithPasswordHash($customer, $quote->getPasswordHash());
$quote->setCustomer($customer);
} else {
$this->customerRepository->save($customer);
}
if (!$quote->getBillingAddress()->getId() && $customer->getDefaultBilling()) {
$quote->getBillingAddress()->importCustomerAddressData($this->customerAddressRepository->getById($customer->getDefaultBilling()));
$quote->getBillingAddress()->setCustomerAddressId($customer->getDefaultBilling());
}
if (!$quote->getShippingAddress()->getSameAsBilling() && !$quote->getBillingAddress()->getId() && $customer->getDefaultShipping()) {
$quote->getShippingAddress()->importCustomerAddressData($this->customerAddressRepository->getById($customer->getDefaultShipping()));
$quote->getShippingAddress()->setCustomerAddressId($customer->getDefaultShipping());
}
}
示例8: _setCustomerAddressAndSave
/**
* Assign customer address to quote address and save quote address
*
* @param bool $unsetId
*/
protected function _setCustomerAddressAndSave($unsetId)
{
$shippingAddress = $this->_quote->getShippingAddress();
if ($unsetId) {
$shippingAddress->setId(null);
}
/** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
$addressRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\AddressRepositoryInterface');
$shippingAddress->setSameAsBilling(0)->setCustomerAddressData($addressRepository->getById($this->_customer->getDefaultBilling()))->save();
}
示例9: ignoreAddressValidation
/**
* Make sure addresses will be saved without validation errors
*
* @return void
*/
private function ignoreAddressValidation()
{
$this->_quote->getBillingAddress()->setShouldIgnoreValidation(true);
if (!$this->_quote->getIsVirtual()) {
$this->_quote->getShippingAddress()->setShouldIgnoreValidation(true);
if (!$this->_config->getValue('requireBillingAddress') && !$this->_quote->getBillingAddress()->getEmail()) {
$this->_quote->getBillingAddress()->setSameAsBilling(1);
}
}
}
示例10: validateBeforeSubmit
/**
* Validate quote before submit
*
* @param Quote $quote
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function validateBeforeSubmit(QuoteEntity $quote)
{
if (!$quote->isVirtual()) {
if ($quote->getShippingAddress()->validate() !== true) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please check the shipping address information. %1', implode(' ', $quote->getShippingAddress()->validate())));
}
$method = $quote->getShippingAddress()->getShippingMethod();
$rate = $quote->getShippingAddress()->getShippingRateByCode($method);
if (!$quote->isVirtual() && (!$method || !$rate)) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a shipping method.'));
}
}
if ($quote->getBillingAddress()->validate() !== true) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please check the billing address information. %1', implode(' ', $quote->getBillingAddress()->validate())));
}
if (!$quote->getPayment()->getMethod()) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please select a valid payment method.'));
}
return $this;
}
示例11: disabledQuoteAddressValidation
/**
* Make sure addresses will be saved without validation errors
*
* @param Quote $quote
* @return void
*/
protected function disabledQuoteAddressValidation(Quote $quote)
{
$billingAddress = $quote->getBillingAddress();
$billingAddress->setShouldIgnoreValidation(true);
if (!$quote->getIsVirtual()) {
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setShouldIgnoreValidation(true);
if (!$billingAddress->getEmail()) {
$billingAddress->setSameAsBilling(1);
}
}
}
示例12: testGetMethodForMyCart
/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
*/
public function testGetMethodForMyCart()
{
$this->_markTestAsRestOnly();
$this->quote->load('test_order_1', 'reserved_order_id');
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
$customerTokenService = $this->objectManager->create('Magento\\Integration\\Api\\CustomerTokenServiceInterface');
$token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
/** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */
$shippingAddress = $this->quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true);
$shippingAddress->collectTotals()->save();
$serviceInfo = ['rest' => ['resourcePath' => '/V1/carts/mine/selected-shipping-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, 'token' => $token]];
$result = $this->_webApiCall($serviceInfo, []);
$this->assertEquals('flatrate', $result[ShippingMethodInterface::KEY_CARRIER_CODE]);
$this->assertEquals('flatrate', $result[ShippingMethodInterface::KEY_METHOD_CODE]);
}
示例13: execute
/**
* Execute operation
*
* @param string $shippingMethod
* @param Quote $quote
* @return void
* @throws \InvalidArgumentException
*/
public function execute($shippingMethod, Quote $quote)
{
if (empty($shippingMethod)) {
throw new \InvalidArgumentException('The "shippingMethod" field does not exists.');
}
if (!$quote->getIsVirtual()) {
$shippingAddress = $quote->getShippingAddress();
if ($shippingMethod !== $shippingAddress->getShippingMethod()) {
$this->disabledQuoteAddressValidation($quote);
$shippingAddress->setShippingMethod($shippingMethod);
$shippingAddress->setCollectShippingRates(true);
$quote->collectTotals();
$this->quoteRepository->save($quote);
}
}
}
示例14: initializeAddresses
private function initializeAddresses()
{
$billingAddress = $this->quote->getBillingAddress();
$billingAddress->addData($this->proxyOrder->getBillingAddressData());
$billingAddress->setStreet($billingAddress->getStreet());
$billingAddress->setLimitCarrier('m2eproshipping');
$billingAddress->setShippingMethod('m2eproshipping_m2eproshipping');
$billingAddress->setCollectShippingRates(true);
$billingAddress->setShouldIgnoreValidation($this->proxyOrder->shouldIgnoreBillingAddressValidation());
// ---------------------------------------
$shippingAddress = $this->quote->getShippingAddress();
$shippingAddress->setSameAsBilling(0);
// maybe just set same as billing?
$shippingAddress->addData($this->proxyOrder->getAddressData());
$shippingAddress->setStreet($shippingAddress->getStreet());
$shippingAddress->setLimitCarrier('m2eproshipping');
$shippingAddress->setShippingMethod('m2eproshipping_m2eproshipping');
$shippingAddress->setCollectShippingRates(true);
// ---------------------------------------
}
示例15: getShippingMethods
/**
* Get list of available shipping methods
* @param \Magento\Quote\Model\Quote $quote
* @param array $addressData
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[]
*/
private function getShippingMethods(Quote $quote, array $addressData)
{
$output = [];
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->addData($addressData);
$shippingAddress->setCollectShippingRates(true);
$this->totalsCollector->collectAddressTotals($quote, $shippingAddress);
$shippingRates = $shippingAddress->getGroupedAllShippingRates();
foreach ($shippingRates as $carrierRates) {
foreach ($carrierRates as $rate) {
$output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
}
}
return $output;
}