本文整理汇总了PHP中Magento\Quote\Model\Quote::getBillingAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP Quote::getBillingAddress方法的具体用法?PHP Quote::getBillingAddress怎么用?PHP Quote::getBillingAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\Quote
的用法示例。
在下文中一共展示了Quote::getBillingAddress方法的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: testSameAsBillingForBillingAddress
/**
* same_as_billing must be equal 0 if billing address is being saved
*
* @param bool $unsetId
* @dataProvider unsetAddressIdDataProvider
*/
public function testSameAsBillingForBillingAddress($unsetId)
{
$this->_quote->setCustomer($this->_customer);
$address = $this->_quote->getBillingAddress();
if ($unsetId) {
$address->setId(null);
}
/** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
$addressRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\AddressRepositoryInterface');
$customerAddressData = $addressRepository->getById($this->_customer->getDefaultBilling());
$address->setSameAsBilling(0)->setCustomerAddressData($customerAddressData)->save();
$this->assertEquals(0, $this->_quote->getBillingAddress()->getSameAsBilling());
}
示例4: 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;
}
示例5: 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());
}
}
示例6: 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);
}
}
}
示例7: 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;
}
示例8: 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);
}
}
}
示例9: 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);
// ---------------------------------------
}
示例10: getTaxContainer
/**
* {@inheritdoc}
*/
public function getTaxContainer()
{
return $this->_salesModel->getIsVirtual() ? $this->_salesModel->getBillingAddress() : $this->_salesModel->getShippingAddress();
}
示例11: getBillingAddress
/**
* Return quote billing address
*
* @return \Magento\Quote\Model\Quote\Address
*/
public function getBillingAddress()
{
return $this->_quote->getBillingAddress();
}
示例12: updateBillingAddress
/**
* Update billing address
*
* @param Quote $quote
* @param array $details
* @return void
*/
private function updateBillingAddress(Quote $quote, array $details)
{
$billingAddress = $quote->getBillingAddress();
if ($this->config->isRequiredBillingAddress()) {
$this->updateAddressData($billingAddress, $details['billingAddress']);
} else {
$this->updateAddressData($billingAddress, $details['shippingAddress']);
}
$billingAddress->setFirstname($details['firstName']);
$billingAddress->setLastname($details['lastName']);
$billingAddress->setEmail($details['email']);
}
示例13: _prepareCustomerQuote
/**
* Prepare quote for customer order submit
*
* @param Quote $quote
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _prepareCustomerQuote($quote)
{
/** @var Quote $quote */
$billing = $quote->getBillingAddress();
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
$customer = $this->customerRepository->getById($quote->getCustomerId());
$hasDefaultBilling = (bool) $customer->getDefaultBilling();
$hasDefaultShipping = (bool) $customer->getDefaultShipping();
if ($shipping && !$shipping->getSameAsBilling() && (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook())) {
$shippingAddress = $shipping->exportCustomerAddress();
if (!$hasDefaultShipping) {
//Make provided address as default shipping address
$shippingAddress->setIsDefaultShipping(true);
$hasDefaultShipping = true;
}
$quote->addCustomerAddress($shippingAddress);
$shipping->setCustomerAddressData($shippingAddress);
}
if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
$billingAddress = $billing->exportCustomerAddress();
if (!$hasDefaultBilling) {
//Make provided address as default shipping address
if (!$hasDefaultShipping) {
//Make provided address as default shipping address
$billingAddress->setIsDefaultShipping(true);
}
$billingAddress->setIsDefaultBilling(true);
}
$quote->addCustomerAddress($billingAddress);
$billing->setCustomerAddressData($billingAddress);
}
if ($shipping && !$shipping->getCustomerId() && !$hasDefaultBilling) {
$shipping->setIsDefaultBilling(true);
}
}
示例14: setMessage
/**
* Sets the gift message to item or quote.
*
* @param \Magento\Quote\Model\Quote $quote The quote.
* @param string $type The type.
* @param \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage The gift message.
* @param null|int $entityId The entity ID.
* @return void
* @throws \Magento\Framework\Exception\CouldNotSaveException The specified gift message is not available.
* @throws \Magento\Framework\Exception\State\InvalidTransitionException The billing or shipping address is not set.
*/
public function setMessage(\Magento\Quote\Model\Quote $quote, $type, $giftMessage, $entityId = null)
{
if ($quote->getBillingAddress()->getCountryId() === null) {
throw new InvalidTransitionException(__('Billing address is not set'));
}
// check if shipping address is set
if ($quote->getShippingAddress()->getCountryId() === null) {
throw new InvalidTransitionException(__('Shipping address is not set'));
}
$message[$type][$entityId] = ['from' => $giftMessage->getSender(), 'to' => $giftMessage->getRecipient(), 'message' => $giftMessage->getMessage()];
try {
$this->add($message, $quote);
} catch (\Exception $e) {
throw new CouldNotSaveException(__('Could not add gift message to shopping cart'));
}
}
示例15: prepareGuestQuote
/**
* Prepare quote for guest checkout order submit
*
* @param Quote $quote
* @return void
*/
private function prepareGuestQuote(Quote $quote)
{
$quote->setCustomerId(null)->setCustomerEmail($quote->getBillingAddress()->getEmail())->setCustomerIsGuest(true)->setCustomerGroupId(Group::NOT_LOGGED_IN_ID);
}