本文整理匯總了PHP中Magento\Quote\Model\Quote::getAddressById方法的典型用法代碼示例。如果您正苦於以下問題:PHP Quote::getAddressById方法的具體用法?PHP Quote::getAddressById怎麽用?PHP Quote::getAddressById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Quote\Model\Quote
的用法示例。
在下文中一共展示了Quote::getAddressById方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: add
/**
* @param array $giftMessages
* @param \Magento\Quote\Model\Quote $quote
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function add($giftMessages, $quote)
{
if (!is_array($giftMessages)) {
return $this;
}
// types are 'quote', 'quote_item', etc
foreach ($giftMessages as $type => $giftMessageEntities) {
foreach ($giftMessageEntities as $entityId => $message) {
$giftMessage = $this->messageFactory->create();
switch ($type) {
case 'quote':
$entity = $quote;
break;
case 'quote_item':
$entity = $quote->getItemById($entityId);
break;
case 'quote_address':
$entity = $quote->getAddressById($entityId);
break;
case 'quote_address_item':
$entity = $quote->getAddressById($message['address'])->getItemById($entityId);
break;
default:
$entity = $quote;
break;
}
if ($entity->getGiftMessageId()) {
$giftMessage->load($entity->getGiftMessageId());
}
if (trim($message['message']) == '') {
if ($giftMessage->getId()) {
try {
$giftMessage->delete();
$entity->setGiftMessageId(0)->save();
} catch (\Exception $e) {
}
}
continue;
}
try {
$giftMessage->setSender($message['from'])->setRecipient($message['to'])->setMessage($message['message'])->setCustomerId($quote->getCustomerId())->save();
$entity->setGiftMessageId($giftMessage->getId())->save();
} catch (\Exception $e) {
}
}
}
return $this;
}
示例2: testGetAddressById
/**
* @dataProvider dataProviderGetAddress
*/
public function testGetAddressById($addressId, $expected)
{
$id = 1;
$this->quoteAddressCollectionMock->expects($this->once())->method('setQuoteFilter')->with($id)->will($this->returnSelf());
$this->quoteAddressMock->expects($this->once())->method('getId')->will($this->returnValue($id));
$iterator = new \ArrayIterator([$this->quoteAddressMock]);
$this->quoteAddressCollectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iterator));
$this->quote->setId($id);
$result = $this->quote->getAddressById($addressId);
$this->assertEquals((bool) $expected, (bool) $result);
}