当前位置: 首页>>代码示例>>PHP>>正文


PHP Observer::processCartUpdateBefore方法代码示例

本文整理汇总了PHP中Observer::processCartUpdateBefore方法的典型用法代码示例。如果您正苦于以下问题:PHP Observer::processCartUpdateBefore方法的具体用法?PHP Observer::processCartUpdateBefore怎么用?PHP Observer::processCartUpdateBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Observer的用法示例。


在下文中一共展示了Observer::processCartUpdateBefore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testProcessCartUpdateBefore

 /**
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testProcessCartUpdateBefore()
 {
     $customerId = 1;
     $itemId = 5;
     $itemQty = 123;
     $productId = 321;
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getCart', 'getInfo'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->exactly(2))->method('getEvent')->willReturn($event);
     $quoteItem = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->setMethods(['getProductId', 'getBuyRequest', '__wakeup'])->disableOriginalConstructor()->getMock();
     $buyRequest = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['setQty'])->disableOriginalConstructor()->getMock();
     $infoData = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['toArray'])->disableOriginalConstructor()->getMock();
     $infoData->expects($this->once())->method('toArray')->willReturn([$itemId => ['qty' => $itemQty, 'wishlist' => true]]);
     $cart = $this->getMockBuilder('Magento\\Checkout\\Model\\Cart')->disableOriginalConstructor()->getMock();
     $quote = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->setMethods(['getCustomerId', 'getItemById', 'removeItem', '__wakeup'])->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getCart')->willReturn($cart);
     $event->expects($this->once())->method('getInfo')->willReturn($infoData);
     $cart->expects($this->any())->method('getQuote')->willReturn($quote);
     $quoteItem->expects($this->once())->method('getProductId')->willReturn($productId);
     $quoteItem->expects($this->once())->method('getBuyRequest')->willReturn($buyRequest);
     $buyRequest->expects($this->once())->method('setQty')->with($itemQty)->willReturnSelf();
     $quote->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $quote->expects($this->once())->method('getItemById')->with($itemId)->willReturn($quoteItem);
     $quote->expects($this->once())->method('removeItem')->with($itemId);
     $this->wishlist->expects($this->once())->method('loadByCustomerId')->with($this->logicalOr($customerId, true))->willReturnSelf();
     $this->wishlist->expects($this->once())->method('addNewItem')->with($this->logicalOr($productId, $buyRequest));
     $this->wishlist->expects($this->once())->method('save');
     $this->helper->expects($this->once())->method('calculate');
     /** @var $eventObserver \Magento\Framework\Event\Observer */
     $this->assertSame($this->observer, $this->observer->processCartUpdateBefore($eventObserver));
 }
开发者ID:,项目名称:,代码行数:35,代码来源:


注:本文中的Observer::processCartUpdateBefore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。