本文整理汇总了PHP中Magento\Quote\Model\Quote::getAllVisibleItems方法的典型用法代码示例。如果您正苦于以下问题:PHP Quote::getAllVisibleItems方法的具体用法?PHP Quote::getAllVisibleItems怎么用?PHP Quote::getAllVisibleItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\Quote
的用法示例。
在下文中一共展示了Quote::getAllVisibleItems方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aroundAddItem
public function aroundAddItem(\Magento\Quote\Model\Quote $subject, \Closure $proceed, \Magento\Quote\Model\Quote\Item $item)
{
$product = $item->getProduct();
$attribute = $product->getResource()->getAttribute('enable_subscription');
$value = null;
if ($attribute) {
$value = $attribute->getFrontend()->getValue($product);
}
$flag = 0;
foreach ($subject->getAllVisibleItems() as $item) {
$itemAttrValue = null;
$itemProduct = $item->getProduct();
$itemAttr = $itemProduct->getResource()->getAttribute('enable_subscription');
if ($itemAttr) {
if ($itemAttr->getFrontend()->getValue($itemProduct)) {
$flag = 1;
}
}
}
if ($value && $subject->hasItems() || $flag) {
throw new \Magento\Framework\Exception\LocalizedException(__('Nominal item can be purchased standalone only.'));
}
$proceed($item);
return $subject;
}
示例2: addQuote
/**
* Push quote contents to given tracker
*
* @param \Magento\Quote\Model\Quote $quote
* @param \Henhed\Piwik\Model\Tracker $tracker
* @return \Henhed\Piwik\Helper\Tracker
*/
public function addQuote(Quote $quote, TrackerModel $tracker)
{
foreach ($quote->getAllVisibleItems() as $item) {
$this->addQuoteItem($item, $tracker);
}
$this->addQuoteTotal($quote, $tracker);
return $this;
}
示例3: merge
/**
* Merge quotes
*
* @param Quote $quote
* @return $this
*/
public function merge(Quote $quote)
{
$this->_eventManager->dispatch($this->_eventPrefix . '_merge_before', [$this->_eventObject => $this, 'source' => $quote]);
foreach ($quote->getAllVisibleItems() as $item) {
$found = false;
foreach ($this->getAllItems() as $quoteItem) {
if ($quoteItem->compare($item)) {
$quoteItem->setQty($quoteItem->getQty() + $item->getQty());
$found = true;
break;
}
}
if (!$found) {
$newItem = clone $item;
$this->addItem($newItem);
if ($item->getHasChildren()) {
foreach ($item->getChildren() as $child) {
$newChild = clone $child;
$newChild->setParentItem($newItem);
$this->addItem($newChild);
}
}
}
}
/**
* Init shipping and billing address if quote is new
*/
if (!$this->getId()) {
$this->getShippingAddress();
$this->getBillingAddress();
}
if ($quote->getCouponCode()) {
$this->setCouponCode($quote->getCouponCode());
}
$this->_eventManager->dispatch($this->_eventPrefix . '_merge_after', [$this->_eventObject => $this, 'source' => $quote]);
return $this;
}
示例4: submit
/**
* Delete quote item
*
* @param Quote $quote
* @param array $orderData
* @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|object|void
* @throws \Exception
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function submit(QuoteEntity $quote, $orderData = [])
{
if (!$quote->getAllVisibleItems()) {
$quote->setIsActive(false);
return;
}
return $this->submitQuote($quote, $orderData);
}
示例5: calculateQuoteChecksum
/**
* calculate quote checksum, it's verified after the return from the payment page
* detect fraud attempts (cart modifications during checkout)
*
* @param \Magento\Quote\Model\Quote $quote
*
* @return string
*/
public function calculateQuoteChecksum($quote)
{
$data = round($quote->getGrandTotal(), $this->getPrecision()) . $quote->getBaseCurrencyCode() . $quote->getCustomerEmail();
foreach ($quote->getAllVisibleItems() as $item) {
/** @var \Magento\Quote\Model\Quote\Item $item */
$data .= $item->getSku();
$data .= round($item->getRowTotal(), $this->getPrecision());
$data .= round($item->getTaxAmount(), $this->getPrecision());
}
$address = $quote->getBillingAddress();
$data .= $address->getName() . $address->getCompany() . $address->getCity() . $address->getPostcode() . $address->getCountryId() . $address->getCountry() . $address->getRegion() . $address->getStreetLine(1) . $address->getStreetLine(2);
$address = $quote->getShippingAddress();
$data .= $address->getName() . $address->getCompany() . $address->getCity() . $address->getPostcode() . $address->getCountryId() . $address->getCountry() . $address->getRegion() . $address->getStreetLine(1) . $address->getStreetLine(2);
return hash_hmac('sha512', $data, $this->getConfigData('basicdata/secret'));
}
示例6: sendPaymentFailedEmail
/**
* Send email id payment was failed
*
* @param \Magento\Quote\Model\Quote $checkout
* @param string $message
* @param string $checkoutType
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
{
$this->inlineTranslation->suspend();
$template = $this->scopeConfig->getValue('checkout/payment_failed/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
$copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
$copyMethod = $this->scopeConfig->getValue('checkout/payment_failed/copy_method', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
$bcc = [];
if ($copyTo && $copyMethod == 'bcc') {
$bcc = $copyTo;
}
$_receiver = $this->scopeConfig->getValue('checkout/payment_failed/receiver', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
$sendTo = [['email' => $this->scopeConfig->getValue('trans_email/ident_' . $_receiver . '/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()), 'name' => $this->scopeConfig->getValue('trans_email/ident_' . $_receiver . '/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId())]];
if ($copyTo && $copyMethod == 'copy') {
foreach ($copyTo as $email) {
$sendTo[] = ['email' => $email, 'name' => null];
}
}
$shippingMethod = '';
if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
$data = explode('_', $shippingInfo);
$shippingMethod = $data[0];
}
$paymentMethod = '';
if ($paymentInfo = $checkout->getPayment()) {
$paymentMethod = $paymentInfo->getMethod();
}
$items = '';
foreach ($checkout->getAllVisibleItems() as $_item) {
/* @var $_item \Magento\Quote\Model\Quote\Item */
$items .= $_item->getProduct()->getName() . ' x ' . $_item->getQty() . ' ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
}
$total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
foreach ($sendTo as $recipient) {
$transport = $this->_transportBuilder->setTemplateIdentifier($template)->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()])->setTemplateVars(['reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => $this->_localeDate->formatDateTime(new \DateTime(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => $this->scopeConfig->getValue('carriers/' . $shippingMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'paymentMethod' => $this->scopeConfig->getValue('payment/' . $paymentMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'items' => nl2br($items), 'total' => $total])->setFrom($this->scopeConfig->getValue('checkout/payment_failed/identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()))->addTo($recipient['email'], $recipient['name'])->addBcc($bcc)->getTransport();
$transport->sendMessage();
}
$this->inlineTranslation->resume();
return $this;
}
示例7: _collectItemsQtys
/**
* Collect items qty
*
* @param \Magento\Quote\Model\Quote $quote
* @return $this
*/
protected function _collectItemsQtys(\Magento\Quote\Model\Quote $quote)
{
$quote->setItemsCount(0);
$quote->setItemsQty(0);
$quote->setVirtualItemsQty(0);
foreach ($quote->getAllVisibleItems() as $item) {
if ($item->getParentItem()) {
continue;
}
$children = $item->getChildren();
if ($children && $item->isShipSeparately()) {
foreach ($children as $child) {
if ($child->getProduct()->getIsVirtual()) {
$quote->setVirtualItemsQty($quote->getVirtualItemsQty() + $child->getQty() * $item->getQty());
}
}
}
if ($item->getProduct()->getIsVirtual()) {
$quote->setVirtualItemsQty($quote->getVirtualItemsQty() + $item->getQty());
}
$quote->setItemsCount($quote->getItemsCount() + 1);
$quote->setItemsQty((double) $quote->getItemsQty() + $item->getQty());
}
return $this;
}