本文整理汇总了PHP中Magento\Framework\App\Response\RedirectInterface::getRefererUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP RedirectInterface::getRefererUrl方法的具体用法?PHP RedirectInterface::getRefererUrl怎么用?PHP RedirectInterface::getRefererUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\Response\RedirectInterface
的用法示例。
在下文中一共展示了RedirectInterface::getRefererUrl方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeDispatch
/**
* Perform customer authentication and wishlist feature state checks
*
* @param \Magento\Framework\App\ActionInterface $subject
* @param RequestInterface $request
* @return void
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request)
{
if ($this->authenticationState->isEnabled() && !$this->customerSession->authenticate($subject)) {
$subject->getActionFlag()->set('', 'no-dispatch', true);
if (!$this->customerSession->getBeforeWishlistUrl()) {
$this->customerSession->setBeforeWishlistUrl($this->redirector->getRefererUrl());
}
$this->customerSession->setBeforeWishlistRequest($request->getParams());
}
if (!$this->config->isSetFlag('wishlist/general/active')) {
throw new NotFoundException(__('Page not found.'));
}
}
示例2: execute
/**
* Check CAPTCHA on New Testmonial page
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'testimonial_new';
$captcha = $this->_helper->getCaptcha($formId);
if ($captcha->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->_testimonialSession->setFormData($controller->getRequest()->getPost());
$this->messageManager->addError(__('Incorrect CAPTCHA.'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), $this->redirect->getRefererUrl());
}
}
}
示例3: setRefererUrl
/**
* Set url from referer
*
* @return $this
*/
public function setRefererUrl()
{
$this->url = $this->redirect->getRefererUrl();
return $this;
}
示例4: 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.'));
//.........这里部分代码省略.........
示例5: 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;
}