當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Item::getProductId方法代碼示例

本文整理匯總了PHP中Magento\Quote\Model\Quote\Item::getProductId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::getProductId方法的具體用法?PHP Item::getProductId怎麽用?PHP Item::getProductId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Quote\Model\Quote\Item的用法示例。


在下文中一共展示了Item::getProductId方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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());
 }
開發者ID:,項目名稱:,代碼行數:26,代碼來源:

示例2: _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

示例3: compare

 /**
  * Compare two quote items
  *
  * @param Item $target
  * @param Item $compared
  * @return bool
  */
 public function compare(Item $target, Item $compared)
 {
     if ($target->getProductId() != $compared->getProductId()) {
         return false;
     }
     $targetOptions = $this->getOptions($target);
     $comparedOptions = $this->getOptions($compared);
     if (array_diff_key($targetOptions, $comparedOptions) != array_diff_key($comparedOptions, $targetOptions)) {
         return false;
     }
     foreach ($targetOptions as $name => $value) {
         if ($comparedOptions[$name] != $value) {
             return false;
         }
     }
     return true;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:24,代碼來源:Compare.php

示例4: _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();
     }
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:31,代碼來源:Observer.php


注:本文中的Magento\Quote\Model\Quote\Item::getProductId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。