本文整理汇总了PHP中Magento\Checkout\Model\Session::setUseNotice方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::setUseNotice方法的具体用法?PHP Session::setUseNotice怎么用?PHP Session::setUseNotice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Checkout\Model\Session
的用法示例。
在下文中一共展示了Session::setUseNotice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateItem
/**
* Update item in shopping cart (quote)
* $requestInfo - either qty (int) or buyRequest in form of array or \Magento\Framework\Object
* $updatingParams - information on how to perform update, passed to Quote->updateItem() method
*
* @param int $itemId
* @param int|array|\Magento\Framework\Object $requestInfo
* @param null|array|\Magento\Framework\Object $updatingParams
* @return \Magento\Sales\Model\Quote\Item|string
* @throws \Magento\Framework\Model\Exception
*
* @see \Magento\Sales\Model\Quote::updateItem()
*/
public function updateItem($itemId, $requestInfo = null, $updatingParams = null)
{
try {
$item = $this->getQuote()->getItemById($itemId);
if (!$item) {
throw new \Magento\Framework\Model\Exception(__('This quote item does not exist.'));
}
$productId = $item->getProduct()->getId();
$product = $this->_getProduct($productId);
$request = $this->_getProductRequest($requestInfo);
if ($productId) {
$minimumQty = $this->stockItemService->getMinSaleQty($productId);
// 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);
}
}
$result = $this->getQuote()->updateItem($itemId, $request, $updatingParams);
} catch (\Magento\Framework\Model\Exception $e) {
$this->_checkoutSession->setUseNotice(false);
$result = $e->getMessage();
}
/**
* We can get string if updating process had some errors
*/
if (is_string($result)) {
if ($this->_checkoutSession->getUseNotice() === null) {
$this->_checkoutSession->setUseNotice(true);
}
throw new \Magento\Framework\Model\Exception($result);
}
$this->_eventManager->dispatch('checkout_cart_product_update_after', array('quote_item' => $result, 'product' => $product));
$this->_checkoutSession->setLastAddedProductId($productId);
return $result;
}
示例2: validateUserValue
/**
* Validate user input for option
*
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
* @return $this
* @throws \Magento\Framework\Model\Exception
*/
public function validateUserValue($values)
{
$this->_checkoutSession->setUseNotice(false);
$this->setIsValid(false);
$option = $this->getOption();
if (!isset($values[$option->getId()]) && $option->getIsRequire() && !$this->getSkipCheckRequiredOption()) {
throw new Exception(__('Please specify the product\'s required option(s).'));
} elseif (isset($values[$option->getId()])) {
$this->setUserValue($values[$option->getId()]);
$this->setIsValid(true);
}
return $this;
}