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


PHP Observer::processAddToCart方法代码示例

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


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

示例1: testProcessAddToCart

 public function testProcessAddToCart()
 {
     $wishlistId = 1;
     $customerId = 2;
     $url = 'http://some.pending/url';
     $message = 'some error msg';
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getRequest', 'getResponse'])->disableOriginalConstructor()->getMock();
     $request = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->getMock();
     $response = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->setMethods(['setRedirect'])->getMockForAbstractClass();
     $wishlists = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Wishlist\\Collection')->disableOriginalConstructor()->getMock();
     $loadedWishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist\\Item')->setMethods(['getId', 'delete'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->any())->method('getEvent')->willReturn($event);
     $request->expects($this->any())->method('getParam')->with('wishlist_next')->willReturn(true);
     $event->expects($this->once())->method('getRequest')->willReturn($request);
     $this->checkoutSession->expects($this->once())->method('getSharedWishlist');
     $this->checkoutSession->expects($this->once())->method('getWishlistPendingMessages')->willReturn([$message]);
     $this->checkoutSession->expects($this->once())->method('getWishlistPendingUrls')->willReturn([$url]);
     $this->checkoutSession->expects($this->once())->method('getWishlistIds');
     $this->checkoutSession->expects($this->once())->method('getSingleWishlistId')->willReturn($wishlistId);
     $this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->wishlist->expects($this->once())->method('loadByCustomerId')->with($this->logicalOr($customerId, true))->willReturnSelf();
     $this->wishlist->expects($this->once())->method('getItemCollection')->willReturn($wishlists);
     $loadedWishlist->expects($this->once())->method('getId')->willReturn($wishlistId);
     $loadedWishlist->expects($this->once())->method('delete');
     $wishlists->expects($this->once())->method('load')->willReturn([$loadedWishlist]);
     $this->checkoutSession->expects($this->once())->method('setWishlistIds')->with([])->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setSingleWishlistId')->with(null)->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setWishlistPendingUrls')->with([])->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setWishlistPendingMessages')->with([])->willReturnSelf();
     $this->messageManager->expects($this->once())->method('addError')->with($message)->willReturnSelf();
     $event->expects($this->once())->method('getResponse')->willReturn($response);
     $response->expects($this->once())->method('setRedirect')->with($url);
     $this->checkoutSession->expects($this->once())->method('setNoCartRedirect')->with(true);
     /** @var $eventObserver \Magento\Framework\Event\Observer */
     $this->observer->processAddToCart($eventObserver);
 }
开发者ID:,项目名称:,代码行数:38,代码来源:


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