本文整理汇总了PHP中Magento\Quote\Model\Quote\Item类的典型用法代码示例。如果您正苦于以下问题:PHP Item类的具体用法?PHP Item怎么用?PHP Item使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Item类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:dragonsword007008,项目名称:magento2,代码行数:25,代码来源:PluginRender.php
示例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);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:QtyProcessor.php
示例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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Compare.php
示例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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:ItemConverter.php
示例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, []));
}
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:ToOrderItemTest.php
示例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;
}
开发者ID:niranjanssiet,项目名称:magento2,代码行数:19,代码来源:ItemIdProcessor.php
示例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();
}
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:19,代码来源:ProductQty.php
示例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);
}
开发者ID:ViniciusAugusto,项目名称:magento2,代码行数:7,代码来源:ValidatorTest.php
示例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));
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:CompareTest.php
示例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));
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:8,代码来源:ItemTest.php
示例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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:23,代码来源:ToOrderItem.php
示例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;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:40,代码来源:Option.php
示例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());
}
开发者ID:,项目名称:,代码行数:17,代码来源:
示例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');
}
}
开发者ID:,项目名称:,代码行数:12,代码来源:
示例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;
}
开发者ID:niranjanssiet,项目名称:magento2,代码行数:16,代码来源:Quote.php
示例16: _removeItem
/**
* Remove item
*
* @param Address $address
* @param AddressItem|Item $item
* @return $this
*/
protected function _removeItem($address, $item)
{
if ($item instanceof Item) {
$address->removeItem($item->getId());
if ($address->getQuote()) {
$address->getQuote()->removeItem($item->getId());
}
} elseif ($item instanceof AddressItem) {
$address->removeItem($item->getId());
if ($address->getQuote()) {
$address->getQuote()->removeItem($item->getQuoteItemId());
}
}
return $this;
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:22,代码来源:Subtotal.php
示例17: getAdditionalData
public function getAdditionalData(\Magento\Quote\Model\Quote\Item $quoteItem)
{
$additionalData = $this->proxyItem->getAdditionalData();
$existAdditionalData = $quoteItem->getAdditionalData();
$existAdditionalData = is_string($existAdditionalData) ? @unserialize($existAdditionalData) : [];
return serialize(array_merge((array) $existAdditionalData, $additionalData));
}
开发者ID:Doability,项目名称:magento2dev,代码行数:7,代码来源:Item.php
示例18: setItem
/**
* Set quote item
*
* @param \Magento\Quote\Model\Quote\Item $item
* @return $this
*/
public function setItem($item)
{
$this->setItemId($item->getId());
$this->_item = $item;
return $this;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:Option.php
示例19: _addQuoteItemError
/**
* Add error to Quote Item
*
* @param \Magento\Quote\Model\Quote\Item $item
* @param string $itemError
* @param string $quoteError
* @param string $errorIndex
* @return $this
*/
protected function _addQuoteItemError(\Magento\Quote\Model\Quote\Item $item, $itemError, $quoteError, $errorIndex = 'error')
{
$item->setHasError(true);
$item->setMessage($itemError);
$item->setQuoteMessage($quoteError);
$item->setQuoteMessageIndex($errorIndex);
return $this;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:Item.php
示例20: getItemData
/**
* {@inheritdoc}
*/
public function getItemData(Item $item)
{
$this->item = $item;
return \array_merge(['product_type' => $item->getProductType()], $this->doGetItemData());
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:8,代码来源:AbstractItem.php
注:本文中的Magento\Quote\Model\Quote\Item类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论