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


PHP Helper\Data類代碼示例

本文整理匯總了PHP中Magento\Wishlist\Helper\Data的典型用法代碼示例。如果您正苦於以下問題:PHP Data類的具體用法?PHP Data怎麽用?PHP Data使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Data類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: execute

 /**
  * Check move quote item to wishlist request
  *
  * @param   Observer $observer
  * @return  $this
  */
 public function execute(Observer $observer)
 {
     $cart = $observer->getEvent()->getCart();
     $data = $observer->getEvent()->getInfo()->toArray();
     $productIds = [];
     $wishlist = $this->getWishlist($cart->getQuote()->getCustomerId());
     if (!$wishlist) {
         return $this;
     }
     /**
      * Collect product ids marked for move to wishlist
      */
     foreach ($data as $itemId => $itemInfo) {
         if (!empty($itemInfo['wishlist']) && ($item = $cart->getQuote()->getItemById($itemId))) {
             $productId = $item->getProductId();
             $buyRequest = $item->getBuyRequest();
             if (array_key_exists('qty', $itemInfo) && is_numeric($itemInfo['qty'])) {
                 $buyRequest->setQty($itemInfo['qty']);
             }
             $wishlist->addNewItem($productId, $buyRequest);
             $productIds[] = $productId;
             $cart->getQuote()->removeItem($itemId);
         }
     }
     if (count($productIds)) {
         $wishlist->save();
         $this->wishlistData->calculate();
     }
     return $this;
 }
開發者ID:IlyaGluschenko,項目名稱:protection,代碼行數:36,代碼來源:CartUpdateBefore.php

示例2: testExecute

 /**
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecute()
 {
     $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\\DataObject')->setMethods(['setQty'])->disableOriginalConstructor()->getMock();
     $infoData = $this->getMockBuilder('Magento\\Framework\\DataObject')->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->execute($eventObserver));
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:35,代碼來源:CartUpdateBeforeTest.php

示例3: testGetSharedAddAllToCartUrl

 public function testGetSharedAddAllToCartUrl()
 {
     $url = 'result url';
     $this->store->expects($this->once())->method('getUrl')->with('*/*/allcart', ['_current' => true])->willReturn($url);
     $this->postDataHelper->expects($this->once())->method('getPostData')->with($url)->willReturn($url);
     $this->assertEquals($url, $this->model->getSharedAddAllToCartUrl());
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:7,代碼來源:DataTest.php

示例4: getName

 /**
  * Retrieve wishlist name
  *
  * @return string
  */
 public function getName()
 {
     $name = $this->_getData('name');
     if (!strlen($name)) {
         return $this->_wishlistData->getDefaultWishlistName();
     }
     return $name;
 }
開發者ID:pavelnovitsky,項目名稱:magento2,代碼行數:13,代碼來源:Wishlist.php

示例5: _prepareLayout

 /**
  * Configure product view blocks
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     // Set custom add to cart url
     $block = $this->getLayout()->getBlock('product.info');
     if ($block && $this->getWishlistItem()) {
         $url = $this->_wishlistData->getAddToCartUrl($this->getWishlistItem());
         $block->setCustomAddToCartUrl($url);
     }
     return parent::_prepareLayout();
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:15,代碼來源:Configure.php

示例6: setUp

 protected function setUp()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['getId', 'getSharingCode'], [], '', false);
     $wishlist->expects($this->any())->method('getId')->will($this->returnValue(5));
     $wishlist->expects($this->any())->method('getSharingCode')->will($this->returnValue('somesharingcode'));
     $customer = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $customer->expects($this->any())->method('getId')->will($this->returnValue(8));
     $customer->expects($this->any())->method('getEmail')->will($this->returnValue('test@example.com'));
     $this->wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', ['getWishlist', 'getCustomer', 'urlEncode'], [], '', false);
     $this->urlEncoder = $this->getMock('Magento\\Framework\\Url\\EncoderInterface', ['encode'], [], '', false);
     $this->wishlistHelper->expects($this->any())->method('getWishlist')->will($this->returnValue($wishlist));
     $this->wishlistHelper->expects($this->any())->method('getCustomer')->will($this->returnValue($customer));
     $this->urlEncoder->expects($this->any())->method('encode')->willReturnCallback(function ($url) {
         return strtr(base64_encode($url), '+/=', '-_,');
     });
     $this->urlBuilder = $this->getMock('Magento\\Framework\\App\\Rss\\UrlBuilderInterface');
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->link = $this->objectManagerHelper->getObject('Magento\\Wishlist\\Block\\Rss\\EmailLink', ['wishlistHelper' => $this->wishlistHelper, 'rssUrlBuilder' => $this->urlBuilder, 'urlEncoder' => $this->urlEncoder]);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:19,代碼來源:EmailLinkTest.php

示例7: testGetSectionDataWithoutItems

 public function testGetSectionDataWithoutItems()
 {
     $items = [];
     $result = ['counter' => null, 'items' => []];
     $this->wishlistHelperMock->expects($this->once())->method('getItemCount')->willReturn(count($items));
     $this->viewMock->expects($this->never())->method('loadLayout');
     $this->wishlistHelperMock->expects($this->never())->method('getWishlistItemCollection');
     $this->catalogImageHelperMock->expects($this->never())->method('init');
     $this->catalogImageHelperMock->expects($this->never())->method('getUrl');
     $this->catalogImageHelperMock->expects($this->never())->method('getLabel');
     $this->catalogImageHelperMock->expects($this->never())->method('getWidth');
     $this->catalogImageHelperMock->expects($this->never())->method('getHeight');
     $this->wishlistHelperMock->expects($this->never())->method('getProductUrl');
     $this->sidebarMock->expects($this->never())->method('getProductPriceHtml');
     $this->wishlistHelperMock->expects($this->never())->method('getAddToCartParams');
     $this->wishlistHelperMock->expects($this->never())->method('getRemoveParams');
     $this->assertEquals($result, $this->model->getSectionData());
 }
開發者ID:whoople,項目名稱:magento2-testing,代碼行數:18,代碼來源:WishlistTest.php

示例8: testExecuteWithoutQuantityArrayAndConfigurable

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithoutQuantityArrayAndConfigurable()
 {
     $itemId = 2;
     $wishlistId = 1;
     $qty = [];
     $productId = 4;
     $indexUrl = 'index_url';
     $configureUrl = 'configure_url';
     $options = [5 => 'option'];
     $params = ['item' => $itemId, 'qty' => $qty];
     $this->formKeyValidator->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $itemMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getWishlistId', 'setQty', 'setOptions', 'getBuyRequest', 'mergeBuyRequest', 'addToCart', 'getProduct', 'getProductId'])->getMock();
     $this->requestMock->expects($this->at(0))->method('getParam')->with('item', null)->willReturn($itemId);
     $this->itemFactoryMock->expects($this->once())->method('create')->willReturn($itemMock);
     $itemMock->expects($this->once())->method('load')->with($itemId, null)->willReturnSelf();
     $itemMock->expects($this->exactly(2))->method('getId')->willReturn($itemId);
     $itemMock->expects($this->once())->method('getWishlistId')->willReturn($wishlistId);
     $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->with($wishlistId)->willReturn($wishlistMock);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('qty', null)->willReturn($qty);
     $this->quantityProcessorMock->expects($this->once())->method('process')->with(1)->willReturnArgument(0);
     $itemMock->expects($this->once())->method('setQty')->with(1)->willReturnSelf();
     $this->urlMock->expects($this->at(0))->method('getUrl')->with('*/*', null)->willReturn($indexUrl);
     $itemMock->expects($this->once())->method('getProductId')->willReturn($productId);
     $this->urlMock->expects($this->at(1))->method('getUrl')->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId])->willReturn($configureUrl);
     $optionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\Option')->disableOriginalConstructor()->getMock();
     $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($optionMock);
     $optionsMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\ResourceModel\\Item\\Option\\Collection')->disableOriginalConstructor()->getMock();
     $optionMock->expects($this->once())->method('getCollection')->willReturn($optionsMock);
     $optionsMock->expects($this->once())->method('addItemFilter')->with([$itemId])->willReturnSelf();
     $optionsMock->expects($this->once())->method('getOptionsByItem')->with($itemId)->willReturn($options);
     $itemMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf();
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $buyRequestMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->once())->method('getBuyRequest')->willReturn($buyRequestMock);
     $this->productHelperMock->expects($this->once())->method('addParamsToBuyRequest')->with($params, ['current_config' => $buyRequestMock])->willReturn($buyRequestMock);
     $itemMock->expects($this->once())->method('mergeBuyRequest')->with($buyRequestMock)->willReturnSelf();
     $itemMock->expects($this->once())->method('addToCart')->with($this->checkoutCartMock, true)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
     $this->messageManagerMock->expects($this->once())->method('addNotice')->with('message', null)->willReturnSelf();
     $this->helperMock->expects($this->once())->method('calculate')->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($configureUrl)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->model->execute());
 }
開發者ID:hientruong90,項目名稱:magento2_installer,代碼行數:46,代碼來源:CartTest.php

示例9: execute

 /**
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     $this->wishlistData->calculate();
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:8,代碼來源:CustomerLogin.php

示例10: getWishlist

 /**
  * Retrieve current wishlist
  *
  * @return \Magento\Wishlist\Model\Wishlist
  */
 public function getWishlist()
 {
     return $this->_wishlistData->getWishlist();
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:9,代碼來源:Button.php

示例11: testExecute

 public function testExecute()
 {
     $event = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     /** @var $event \Magento\Framework\Event\Observer */
     $this->helper->expects($this->once())->method('calculate');
     $this->observer->execute($event);
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:7,代碼來源:CustomerLoginTest.php

示例12: execute

 /**
  * Add cart item to wishlist and remove from cart
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @throws NotFoundException
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function execute()
 {
     $wishlist = $this->wishlistProvider->getWishlist();
     if (!$wishlist) {
         throw new NotFoundException(__('Page not found.'));
     }
     try {
         $itemId = (int) $this->getRequest()->getParam('item');
         $item = $this->cart->getQuote()->getItemById($itemId);
         if (!$item) {
             throw new LocalizedException(__('The requested cart item doesn\'t exist.'));
         }
         $productId = $item->getProductId();
         $buyRequest = $item->getBuyRequest();
         $wishlist->addNewItem($productId, $buyRequest);
         $this->cart->getQuote()->removeItem($itemId);
         $this->cart->save();
         $this->wishlistHelper->calculate();
         $wishlist->save();
         $this->messageManager->addSuccessMessage(__("%1 has been moved to your wish list.", $this->escaper->escapeHtml($item->getProduct()->getName())));
     } catch (LocalizedException $e) {
         $this->messageManager->addErrorMessage($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addExceptionMessage($e, __('We can\'t move the item to the wish list.'));
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setUrl($this->cartHelper->getCartUrl());
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:36,代碼來源:Fromcart.php

示例13: _toHtml

 /**
  * @return string
  */
 protected function _toHtml()
 {
     if ($this->_wishlistHelper->isAllow()) {
         return parent::_toHtml();
     }
     return '';
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:10,代碼來源:Link.php

示例14: testGetMoveFromCartParams

 public function testGetMoveFromCartParams()
 {
     $itemId = 45;
     $json = '{json;}';
     /**
      * @var Item|\PHPUnit_Framework_MockObject_MockObject $itemMock
      */
     $itemMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->once())->method('getId')->willReturn($itemId);
     $this->wishlistHelperMock->expects($this->once())->method('getMoveFromCartParams')->with($itemId)->willReturn($json);
     $this->model->setItem($itemMock);
     $this->assertEquals($json, $this->model->getMoveFromCartParams());
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:13,代碼來源:MoveToWishlistTest.php

示例15: getItems

 /**
  * Get wishlist items
  *
  * @return array
  */
 protected function getItems()
 {
     $this->view->loadLayout();
     $collection = $this->wishlistHelper->getWishlistItemCollection();
     $collection->clear()->setPageSize(self::SIDEBAR_ITEMS_NUMBER)->setInStockFilter(true)->setOrder('added_at');
     $items = [];
     foreach ($collection as $wishlistItem) {
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $wishlistItem->getProduct();
         $this->productImageView->init($product, 'wishlist_sidebar_block', 'Magento_Catalog');
         $items[] = ['image' => ['src' => $this->productImageView->getUrl(), 'alt' => $this->productImageView->getLabel(), 'width' => $this->productImageView->getWidth(), 'height' => $this->productImageView->getHeight()], 'product_url' => $this->wishlistHelper->getProductUrl($wishlistItem), 'product_name' => $product->getName(), 'product_price' => $this->block->getProductPriceHtml($product, \Magento\Catalog\Pricing\Price\ConfiguredPriceInterface::CONFIGURED_PRICE_CODE, \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST, ['item' => $wishlistItem]), 'product_is_saleable_and_visible' => $product->isSaleable() && $product->isVisibleInSiteVisibility(), 'product_has_required_options' => $product->getTypeInstance()->hasRequiredOptions($product), 'add_to_cart_params' => $this->wishlistHelper->getAddToCartParams($wishlistItem), 'delete_item_params' => $this->wishlistHelper->getRemoveParams($wishlistItem)];
     }
     return $items;
 }
開發者ID:vasiljok,項目名稱:magento2,代碼行數:19,代碼來源:Wishlist.php


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