本文整理匯總了PHP中Magento\Wishlist\Helper\Data::getListUrl方法的典型用法代碼示例。如果您正苦於以下問題:PHP Data::getListUrl方法的具體用法?PHP Data::getListUrl怎麽用?PHP Data::getListUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Wishlist\Helper\Data
的用法示例。
在下文中一共展示了Data::getListUrl方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: moveAllToCart
/**
* Move all wishlist item to cart
*
* @param Wishlist $wishlist
* @param array $qtys
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function moveAllToCart(Wishlist $wishlist, $qtys)
{
$isOwner = $wishlist->isOwner($this->customerSession->getCustomerId());
$messages = [];
$addedItems = [];
$notSalable = [];
$hasOptions = [];
$cart = $this->cart;
$collection = $wishlist->getItemCollection()->setVisibilityFilter();
foreach ($collection as $item) {
/** @var \Magento\Wishlist\Model\Item */
try {
$disableAddToCart = $item->getProduct()->getDisableAddToCart();
$item->unsProduct();
// Set qty
if (isset($qtys[$item->getId()])) {
$qty = $this->quantityProcessor->process($qtys[$item->getId()]);
if ($qty) {
$item->setQty($qty);
}
}
$item->getProduct()->setDisableAddToCart($disableAddToCart);
// Add to cart
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
if ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_NOT_SALABLE) {
$notSalable[] = $item;
} elseif ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) {
$hasOptions[] = $item;
} else {
$messages[] = __('%1 for "%2".', trim($e->getMessage(), '.'), $item->getProduct()->getName());
}
$cartItem = $cart->getQuote()->getItemByProduct($item->getProduct());
if ($cartItem) {
$cart->getQuote()->deleteItem($cartItem);
}
} catch (\Exception $e) {
$this->logger->critical($e);
$messages[] = __('We cannot add this item to your shopping cart.');
}
}
if ($isOwner) {
$indexUrl = $this->helper->getListUrl($wishlist->getId());
} else {
$indexUrl = $this->urlBuilder->getUrl('wishlist/shared', ['code' => $wishlist->getSharingCode()]);
}
if ($this->cartHelper->getShouldRedirectToCart()) {
$redirectUrl = $this->cartHelper->getCartUrl();
} elseif ($this->redirector->getRefererUrl()) {
$redirectUrl = $this->redirector->getRefererUrl();
} else {
$redirectUrl = $indexUrl;
}
if ($notSalable) {
$products = [];
foreach ($notSalable as $item) {
$products[] = '"' . $item->getProduct()->getName() . '"';
}
$messages[] = __('We couldn\'t add the following product(s) to the shopping cart: %1.', join(', ', $products));
}
if ($hasOptions) {
$products = [];
foreach ($hasOptions as $item) {
$products[] = '"' . $item->getProduct()->getName() . '"';
}
$messages[] = __('Product(s) %1 have required options. Each product can only be added individually.', join(', ', $products));
}
if ($messages) {
$isMessageSole = count($messages) == 1;
if ($isMessageSole && count($hasOptions) == 1) {
$item = $hasOptions[0];
if ($isOwner) {
$item->delete();
}
$redirectUrl = $item->getProductUrl();
} else {
foreach ($messages as $message) {
$this->messageManager->addError($message);
}
$redirectUrl = $indexUrl;
}
}
if ($addedItems) {
// save wishlist model for setting date of last update
try {
$wishlist->save();
} catch (\Exception $e) {
$this->messageManager->addError(__('We can\'t update wish list.'));
//.........這裏部分代碼省略.........
示例2: moveAllToCart
/**
* Move all wishlist item to cart
*
* @param Wishlist $wishlist
* @param array $qtys
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function moveAllToCart(Wishlist $wishlist, $qtys)
{
$isOwner = $wishlist->isOwner($this->customerSession->getCustomerId());
$messages = [];
$addedProducts = [];
$notSalable = [];
$cart = $this->cart;
$collection = $wishlist->getItemCollection()->setVisibilityFilter();
foreach ($collection as $item) {
/** @var $item \Magento\Wishlist\Model\Item */
try {
$disableAddToCart = $item->getProduct()->getDisableAddToCart();
$item->unsProduct();
// Set qty
if (isset($qtys[$item->getId()])) {
$qty = $this->quantityProcessor->process($qtys[$item->getId()]);
if ($qty) {
$item->setQty($qty);
}
}
$item->getProduct()->setDisableAddToCart($disableAddToCart);
// Add to cart
if ($item->addToCart($cart, $isOwner)) {
$addedProducts[] = $item->getProduct();
}
} catch (LocalizedException $e) {
if ($e instanceof ProductException) {
$notSalable[] = $item;
} else {
$messages[] = __('%1 for "%2".', trim($e->getMessage(), '.'), $item->getProduct()->getName());
}
$cartItem = $cart->getQuote()->getItemByProduct($item->getProduct());
if ($cartItem) {
$cart->getQuote()->deleteItem($cartItem);
}
} catch (\Exception $e) {
$this->logger->critical($e);
$messages[] = __('We can\'t add this item to your shopping cart right now.');
}
}
if ($isOwner) {
$indexUrl = $this->helper->getListUrl($wishlist->getId());
} else {
$indexUrl = $this->urlBuilder->getUrl('wishlist/shared', ['code' => $wishlist->getSharingCode()]);
}
if ($this->cartHelper->getShouldRedirectToCart()) {
$redirectUrl = $this->cartHelper->getCartUrl();
} elseif ($this->redirector->getRefererUrl()) {
$redirectUrl = $this->redirector->getRefererUrl();
} else {
$redirectUrl = $indexUrl;
}
if ($notSalable) {
$products = [];
foreach ($notSalable as $item) {
$products[] = '"' . $item->getProduct()->getName() . '"';
}
$messages[] = __('We couldn\'t add the following product(s) to the shopping cart: %1.', join(', ', $products));
}
if ($messages) {
foreach ($messages as $message) {
$this->messageManager->addError($message);
}
$redirectUrl = $indexUrl;
}
if ($addedProducts) {
// save wishlist model for setting date of last update
try {
$wishlist->save();
} catch (\Exception $e) {
$this->messageManager->addError(__('We can\'t update the Wish List right now.'));
$redirectUrl = $indexUrl;
}
$products = [];
foreach ($addedProducts as $product) {
/** @var $product \Magento\Catalog\Model\Product */
$products[] = '"' . $product->getName() . '"';
}
$this->messageManager->addSuccess(__('%1 product(s) have been added to shopping cart: %2.', count($addedProducts), join(', ', $products)));
// save cart and collect totals
$cart->save()->getQuote()->collectTotals();
}
$this->helper->calculate();
return $redirectUrl;
}