本文整理匯總了PHP中Magento\Quote\Model\Quote\Item::getProduct方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::getProduct方法的具體用法?PHP Item::getProduct怎麽用?PHP Item::getProduct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Quote\Model\Quote\Item
的用法示例。
在下文中一共展示了Item::getProduct方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSetProductWithQuoteAndStockItem
public function testSetProductWithQuoteAndStockItem()
{
$productMock = $this->generateProductMock(self::PRODUCT_ID, self::PRODUCT_TYPE, self::PRODUCT_SKU, self::PRODUCT_NAME, self::PRODUCT_WEIGHT, self::PRODUCT_TAX_CLASS_ID, self::PRODUCT_COST);
$this->eventDispatcher->expects($this->once())->method('dispatch')->with('sales_quote_item_set_product', ['product' => $productMock, 'quote_item' => $this->model]);
$isQtyDecimal = true;
$this->stockItemMock->expects($this->any())->method('getStockId')->will($this->returnValue(99));
$this->stockItemMock->expects($this->once())->method('getIsQtyDecimal')->will($this->returnValue($isQtyDecimal));
$storeId = 15;
$customerGroupId = 11;
$quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getStoreId', 'getCustomerGroupId', '__wakeup'])->getMock();
$quoteMock->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId));
$quoteMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($customerGroupId));
$this->model->setQuote($quoteMock);
$productMock->expects($this->once())->method('setStoreId')->with($storeId);
$productMock->expects($this->once())->method('setCustomerGroupId')->with($customerGroupId);
$this->model->setProduct($productMock);
$this->assertEquals($productMock, $this->model->getProduct());
$this->assertEquals(self::PRODUCT_ID, $this->model->getProductId());
$this->assertEquals(self::PRODUCT_TYPE, $this->model->getRealProductType());
$this->assertEquals(self::PRODUCT_SKU, $this->model->getSku());
$this->assertEquals(self::PRODUCT_NAME, $this->model->getName());
$this->assertEquals(self::PRODUCT_WEIGHT, $this->model->getWeight());
$this->assertEquals(self::PRODUCT_TAX_CLASS_ID, $this->model->getTaxClassId());
$this->assertEquals(self::PRODUCT_COST, $this->model->getBaseCost());
$this->assertEquals($isQtyDecimal, $this->model->getIsQtyDecimal());
}
示例2: 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;
}
示例3: getQtyForCheck
/**
* @param int $qty
* @return int
*/
public function getQtyForCheck($qty)
{
if (!$this->item->getParentItem()) {
$increaseQty = $this->item->getQtyToAdd() ? $this->item->getQtyToAdd() : $qty;
return $this->quoteItemQtyList->getQty($this->item->getProduct()->getId(), $this->item->getId(), $this->item->getQuoteId(), $increaseQty);
}
return $this->quoteItemQtyList->getQty($this->item->getProduct()->getId(), $this->item->getId(), $this->item->getQuoteId(), 0);
}
示例4: convert
/**
* @param Item|AddressItem $item
* @param array $data
* @return OrderItemInterface
*/
public function convert($item, $data = [])
{
$options = $item->getProductOrderOptions();
if (!$options) {
$options = $item->getProduct()->getTypeInstance()->getOrderOptions($item->getProduct());
}
$orderItemData = $this->objectCopyService->getDataFromFieldset('quote_convert_item', 'to_order_item', $item);
if (!$item->getNoDiscount()) {
$data = array_merge($data, $this->objectCopyService->getDataFromFieldset('quote_convert_item', 'to_order_item_discount', $item));
}
$orderItem = $this->orderItemFactory->create();
$this->dataObjectHelper->populateWithArray($orderItem, array_merge($orderItemData, $data), '\\Magento\\Sales\\Api\\Data\\OrderItemInterface');
$orderItem->setProductOptions($options);
if ($item->getParentItem()) {
$orderItem->setQtyOrdered($orderItemData[OrderItemInterface::QTY_ORDERED] * $item->getParentItem()->getQty());
}
return $orderItem;
}
示例5: initialize
/**
* Initialize stock item
*
* @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
* @param \Magento\Quote\Model\Quote\Item $quoteItem
* @param int $qty
*
* @return \Magento\Framework\DataObject
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function initialize(\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem, \Magento\Quote\Model\Quote\Item $quoteItem, $qty)
{
/**
* When we work with subitem
*/
if ($quoteItem->getParentItem()) {
$rowQty = $quoteItem->getParentItem()->getQty() * $qty;
/**
* we are using 0 because original qty was processed
*/
$qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), 0);
} else {
$increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
$rowQty = $qty;
$qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseQty);
}
$productTypeCustomOption = $quoteItem->getProduct()->getCustomOption('product_type');
if ($productTypeCustomOption !== null) {
// Check if product related to current item is a part of product that represents product set
if ($this->typeConfig->isProductSet($productTypeCustomOption->getValue())) {
$stockItem->setIsChildItem(true);
}
}
$stockItem->setProductName($quoteItem->getProduct()->getName());
$result = $this->stockState->checkQuoteItemQty($quoteItem->getProduct()->getId(), $rowQty, $qtyForCheck, $qty, $quoteItem->getProduct()->getStore()->getWebsiteId());
if ($stockItem->hasIsChildItem()) {
$stockItem->unsIsChildItem();
}
if ($result->getItemIsQtyDecimal() !== null) {
$quoteItem->setIsQtyDecimal($result->getItemIsQtyDecimal());
if ($quoteItem->getParentItem()) {
$quoteItem->getParentItem()->setIsQtyDecimal($result->getItemIsQtyDecimal());
}
}
/**
* Just base (parent) item qty can be changed
* qty of child products are declared just during add process
* exception for updating also managed by product type
*/
if ($result->getHasQtyOptionUpdate() && (!$quoteItem->getParentItem() || $quoteItem->getParentItem()->getProduct()->getTypeInstance()->getForceChildItemQtyChanges($quoteItem->getParentItem()->getProduct()))) {
$quoteItem->setData('qty', $result->getOrigQty());
}
if ($result->getItemUseOldQty() !== null) {
$quoteItem->setUseOldQty($result->getItemUseOldQty());
}
if ($result->getMessage() !== null) {
$quoteItem->setMessage($result->getMessage());
}
if ($result->getItemBackorders() !== null) {
$quoteItem->setBackorders($result->getItemBackorders());
}
return $result;
}
示例6: isMoveToWishlistAllowed
/**
* Returns whether moving to wishlist is allowed for this item
*
* @param Item $item
* @return bool
*/
public function isMoveToWishlistAllowed($item)
{
return $item->getProduct()->isVisibleInSiteVisibility();
}
示例7: _prepareOptionsForRequest
/**
* Prepare options array for info buy request
*
* @param \Magento\Quote\Model\Quote\Item $item
* @return array
*/
protected function _prepareOptionsForRequest($item)
{
$newInfoOptions = [];
$optionIds = $item->getOptionByCode('option_ids');
if ($optionIds) {
foreach (explode(',', $optionIds->getValue()) as $optionId) {
$option = $item->getProduct()->getOptionById($optionId);
$optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
$group = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Option')->groupFactory($option->getType())->setOption($option)->setQuoteItem($item);
$newInfoOptions[$optionId] = $group->prepareOptionValueForRequest($optionValue);
}
}
return $newInfoOptions;
}
示例8: _addItemToQtyArray
/**
* Adds stock item qty to $items (creates new entry or increments existing one)
* $items is array with following structure:
* array(
* $productId => array(
* 'qty' => $qty,
* 'item' => $stockItems|null
* )
* )
*
* @param QuoteItem $quoteItem
* @param array &$items
* @return void
*/
protected function _addItemToQtyArray(QuoteItem $quoteItem, &$items)
{
$productId = $quoteItem->getProductId();
if (!$productId) {
return;
}
if (isset($items[$productId])) {
$items[$productId] += $quoteItem->getTotalQty();
} else {
$stockItem = null;
if ($quoteItem->getProduct()) {
/** @var Item $stockItem */
$stockItem = $this->stockRegistry->getStockItem($quoteItem->getProduct()->getId(), $quoteItem->getStore()->getWebsiteId());
}
$items[$productId] = $quoteItem->getTotalQty();
}
}
示例9: getProductId
/**
* Retrieve product identifier linked with item
*
* @param \Magento\Quote\Model\Quote\Item $item
* @return int
*/
public function getProductId($item)
{
return $item->getProduct()->getId();
}
示例10: buildItemId
/**
* @param Item $item
* @return string
*/
protected function buildItemId(Item $item)
{
/** @var Item $parentItem */
$parentItem = $item->getOptionByCode('product_type');
if (!is_null($parentItem)) {
return $parentItem->getProduct()->getSku();
} elseif ($item->getProductType() === 'simple') {
// todo: if the product has a configurable parent and there is "super_attribute" data in the buy request, assume we need to use the parent product SKU, just like in Magento 1.
}
return $item->getProduct()->getSku();
}
示例11: unsetCustomPrice
/**
* Unset custom_price data for quote item
*
* @param Item $item
* @return void
*/
protected function unsetCustomPrice(Item $item)
{
/** @var \Magento\Framework\DataObject $infoBuyRequest */
$infoBuyRequest = $item->getBuyRequest();
if ($infoBuyRequest->hasData('custom_price')) {
$infoBuyRequest->unsetData('custom_price');
$infoBuyRequest->setValue(serialize($infoBuyRequest->getData()));
$infoBuyRequest->setCode('info_buyRequest');
$infoBuyRequest->setProduct($item->getProduct());
$item->addOption($infoBuyRequest);
}
$item->unsetData('custom_price');
$item->unsetData('original_custom_price');
}