本文整理汇总了PHP中Magento\Quote\Model\Quote::getItemById方法的典型用法代码示例。如果您正苦于以下问题:PHP Quote::getItemById方法的具体用法?PHP Quote::getItemById怎么用?PHP Quote::getItemById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\Quote
的用法示例。
在下文中一共展示了Quote::getItemById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initData
/**
* Loads customer, quote and quote item by request params
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _initData()
{
$this->_customerId = (int) $this->getRequest()->getParam('customer_id');
if (!$this->_customerId) {
throw new \Magento\Framework\Exception\LocalizedException(__('No customer ID defined.'));
}
$quoteItemId = (int) $this->getRequest()->getParam('id');
$websiteId = (int) $this->getRequest()->getParam('website_id');
try {
$this->_quote = $this->quoteRepository->getForCustomer($this->_customerId);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->_quote = $this->quoteRepository->create();
}
$this->_quote->setWebsite($this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getWebsite($websiteId));
$this->_quoteItem = $this->_quote->getItemById($quoteItemId);
if (!$this->_quoteItem) {
throw new LocalizedException(__('Please correct the quote items and try again.'));
}
return $this;
}
示例2: 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;
}