本文整理匯總了PHP中Magento\Quote\Model\Quote\Item類的典型用法代碼示例。如果您正苦於以下問題:PHP Item類的具體用法?PHP Item怎麽用?PHP Item使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Item類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
示例2: 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);
}
示例3: getOptions
/**
* Returns options adopted to compare
*
* @param Item $item
* @return array
*/
public function getOptions(Item $item)
{
$options = [];
foreach ($item->getOptions() as $option) {
$options[$option->getCode()] = $this->getOptionValues($option->getValue());
}
return $options;
}
示例4: modelToDataObject
/**
* Converts a specified rate model to a shipping method data object.
*
* @param \Magento\Quote\Model\Quote\Item $item
* @return array
* @throws \Exception
*/
public function modelToDataObject($item)
{
$this->eventManager->dispatch('items_additional_data', ['item' => $item]);
$items = $item->toArray();
$items['options'] = $this->getFormattedOptionValue($item);
$itemsData = $this->totalsItemFactory->create();
$this->dataObjectHelper->populateWithArray($itemsData, $items, '\\Magento\\Quote\\Api\\Data\\TotalsItemInterface');
return $itemsData;
}
示例5: testConvert
/**
* test for convert method
*/
public function testConvert()
{
$this->quoteItemMock->expects($this->exactly(2))->method('getProduct')->willReturn($this->productMock);
$this->productMock->expects($this->once())->method('getTypeInstance')->willReturn($this->productTypeMock);
$this->productTypeMock->expects($this->once())->method('getOrderOptions')->with($this->productMock)->willReturn(['option']);
$this->objectCopyServiceMock->expects($this->at(0))->method('getDataFromFieldset')->with('quote_convert_item', 'to_order_item', $this->quoteItemMock)->willReturn([]);
$this->objectCopyServiceMock->expects($this->at(1))->method('getDataFromFieldset')->with('quote_convert_item', 'to_order_item_discount', $this->quoteItemMock)->willReturn([]);
$this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock);
$this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Item', $this->converter->convert($this->quoteItemMock, []));
}
示例6: process
/**
* Adds item ID to giftOptionsCartItem configuration and name
*
* @param array $jsLayout
* @param Item $item
* @return array
*/
public function process($jsLayout, Item $item)
{
if (isset($jsLayout['components']['giftOptionsCartItem'])) {
if (!isset($jsLayout['components']['giftOptionsCartItem']['config'])) {
$jsLayout['components']['giftOptionsCartItem']['config'] = [];
}
$jsLayout['components']['giftOptionsCartItem']['config']['itemId'] = $item->getId();
$jsLayout['components']['giftOptionsCartItem-' . $item->getId()] = $jsLayout['components']['giftOptionsCartItem'];
unset($jsLayout['components']['giftOptionsCartItem']);
}
return $jsLayout;
}
示例7: _addItemToQtyArray
/**
* Adds stock item qty to $items (creates new entry or increments existing one)
*
* @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 {
$items[$productId] = $quoteItem->getTotalQty();
}
}
示例8: testInitTotalsNoItems
public function testInitTotalsNoItems()
{
$address = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
$this->item->expects($this->never())->method('getParentItemId');
$this->model->init($this->model->getWebsiteId(), $this->model->getCustomerGroupId(), $this->model->getCouponCode());
$this->model->initTotals([], $address);
}
示例9: testCompareItemWithoutOptionWithCompared
/**
* test compare two items first without options and second with options
*/
public function testCompareItemWithoutOptionWithCompared()
{
$this->itemMock->expects($this->any())->method('getProductId')->will($this->returnValue(1));
$this->comparedMock->expects($this->any())->method('getProductId')->will($this->returnValue(1));
$this->comparedMock->expects($this->any())->method('getOptions')->will($this->returnValue([$this->getOptionMock('option-1', 1), $this->getOptionMock('option-2', 'option-value'), $this->getOptionMock('option-3', serialize(['value' => 'value-1', 'qty' => 2]))]));
$this->itemMock->expects($this->any())->method('getOptions')->will($this->returnValue([]));
$this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
}
示例10: testSaveModifiedItem
public function testSaveModifiedItem()
{
$this->entitySnapshotMock->expects($this->exactly(2))->method('isModified')->with($this->quoteItemMock)->willReturn(true);
$this->quoteItemMock->expects($this->once())->method('isOptionsSaved')->willReturn(false);
$this->quoteItemMock->expects($this->once())->method('saveItemOptions');
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
$this->assertEquals($this->model, $this->model->save($this->quoteItemMock));
}
示例11: 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;
}
示例12: initialize
/**
* Initialize item option
*
* @param \Magento\Quote\Model\Quote\Item\Option $option
* @param \Magento\Quote\Model\Quote\Item $quoteItem
* @param int $qty
*
* @return \Magento\Framework\Object
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function initialize(\Magento\Quote\Model\Quote\Item\Option $option, \Magento\Quote\Model\Quote\Item $quoteItem, $qty)
{
$optionValue = $option->getValue();
$optionQty = $qty * $optionValue;
$increaseOptionQty = ($quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty) * $optionValue;
$qtyForCheck = $this->quoteItemQtyList->getQty($option->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseOptionQty);
$stockItem = $this->getStockItem($option, $quoteItem);
$result = $this->stockState->checkQuoteItemQty($option->getProduct()->getId(), $optionQty, $qtyForCheck, $optionValue, $option->getProduct()->getStore()->getWebsiteId());
if ($result->getItemIsQtyDecimal() !== null) {
$option->setIsQtyDecimal($result->getItemIsQtyDecimal());
}
if ($result->getHasQtyOptionUpdate()) {
$option->setHasQtyOptionUpdate(true);
$quoteItem->updateQtyOption($option, $result->getOrigQty());
$option->setValue($result->getOrigQty());
/**
* if option's qty was updates we also need to update quote item qty
*/
$quoteItem->setData('qty', intval($qty));
}
if ($result->getMessage() !== null) {
$option->setMessage($result->getMessage());
$quoteItem->setMessage($result->getMessage());
}
if ($result->getItemBackorders() !== null) {
$option->setBackorders($result->getItemBackorders());
}
$stockItem->unsIsChildItem();
return $result;
}
示例13: testRemoveErrorInfosByParamsAllErrorsRemoved
public function testRemoveErrorInfosByParamsAllErrorsRemoved()
{
$message = "message";
$message2 = "message2";
$this->errorInfos->expects($this->at(0))->method('addItem')->with(null, null, $message);
$this->errorInfos->expects($this->at(1))->method('addItem')->with(null, null, $message2);
$this->assertEquals($this->model, $this->model->addErrorInfo(null, null, $message));
$this->assertEquals($this->model, $this->model->addErrorInfo(null, null, $message2));
$this->assertEquals($message . "\n" . $message2, $this->model->getMessage());
$params = [];
$removedItems = [['message' => $message], ['message' => $message2]];
$this->errorInfos->expects($this->once())->method('removeItemsByParams')->with($params)->will($this->returnValue($removedItems));
$this->errorInfos->expects($this->once())->method('getItems')->will($this->returnValue([]));
$this->assertEquals($this->model, $this->model->removeErrorInfosByParams($params));
$this->assertFalse($this->model->getHasError());
$this->assertEquals('', $this->model->getMessage());
}
示例14: verifyItem
/**
* Verify that correct fields of item has been set
*
* @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote\Item $item
* @param array $itemData
*/
public function verifyItem(\Magento\Quote\Model\Quote\Item $item, $itemData)
{
foreach ($itemData as $key => $value) {
$this->assertEquals($value, $item->getData($key), 'item ' . $key . ' is incorrect');
}
}
示例15: addItem
/**
* Adding new item to quote
*
* @param \Magento\Quote\Model\Quote\Item $item
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function addItem(\Magento\Quote\Model\Quote\Item $item)
{
$item->setQuote($this);
if (!$item->getId()) {
$this->getItemsCollection()->addItem($item);
$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);
}
return $this;
}