本文整理匯總了PHP中Magento\Checkout\Model\Session::setRedirectUrl方法的典型用法代碼示例。如果您正苦於以下問題:PHP Session::setRedirectUrl方法的具體用法?PHP Session::setRedirectUrl怎麽用?PHP Session::setRedirectUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Checkout\Model\Session
的用法示例。
在下文中一共展示了Session::setRedirectUrl方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addProduct
/**
* Add product to shopping cart (quote)
*
* @param int|Product $productInfo
* @param \Magento\Framework\Object|int|array $requestInfo
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function addProduct($productInfo, $requestInfo = null)
{
$product = $this->_getProduct($productInfo);
$request = $this->_getProductRequest($requestInfo);
$productId = $product->getId();
if ($productId) {
$stockItem = $this->stockRegistry->getStockItem($productId, $product->getStore()->getWebsiteId());
$minimumQty = $stockItem->getMinSaleQty();
//If product was not found in cart and there is set minimal qty for it
if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty && !$this->getQuote()->hasProductId($productId)) {
$request->setQty($minimumQty);
}
}
if ($productId) {
try {
$result = $this->getQuote()->addProduct($product, $request);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->_checkoutSession->setUseNotice(false);
$result = $e->getMessage();
}
/**
* String we can get if prepare process has error
*/
if (is_string($result)) {
if ($product->hasOptionsValidationFail()) {
$redirectUrl = $product->getUrlModel()->getUrl($product, ['_query' => ['startcustomization' => 1]]);
} else {
$redirectUrl = $product->getProductUrl();
}
$this->_checkoutSession->setRedirectUrl($redirectUrl);
if ($this->_checkoutSession->getUseNotice() === null) {
$this->_checkoutSession->setUseNotice(true);
}
throw new \Magento\Framework\Exception\LocalizedException(__($result));
}
} else {
throw new \Magento\Framework\Exception\LocalizedException(__('The product does not exist.'));
}
$this->_eventManager->dispatch('checkout_cart_product_add_after', ['quote_item' => $result, 'product' => $product]);
$this->_checkoutSession->setLastAddedProductId($productId);
return $this;
}