public function testCompareOptionsNegativeOptionsTwoHaveNotOption() { $code = 'someOption'; $optionsOneMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', ['getCode', '__wakeup'], [], '', false); $optionsTwoMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', [], [], '', false); $optionsOneMock->expects($this->once())->method('getCode')->will($this->returnValue($code)); $result = $this->wishlistItem->compareOptions([$code => $optionsOneMock], ['someOneElse' => $optionsTwoMock]); $this->assertFalse($result); }
/** * Load item by wishlist, product and shared stores * * @param \Magento\Wishlist\Model\Item $object * @param int $wishlistId * @param int $productId * @param array $sharedStores * @return $this */ public function loadByProductWishlist($object, $wishlistId, $productId, $sharedStores) { $connection = $this->getConnection(); $storeWhere = $connection->quoteInto('store_id IN (?)', $sharedStores); $select = $connection->select()->from($this->getMainTable())->where('wishlist_id=:wishlist_id AND ' . 'product_id=:product_id AND ' . $storeWhere); $bind = ['wishlist_id' => $wishlistId, 'product_id' => $productId]; $data = $connection->fetchRow($select, $bind); if ($data) { $object->setData($data); } $this->_afterLoad($object); return $this; }
public function testCompareOptionsNegativeOptionsTwoHaveNotOption() { $code = 'someOption'; $optionsOneMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['getCode', '__wakeup'])->getMock(); $optionsTwoMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock(); $optionsOneMock->expects($this->once())->method('getCode')->will($this->returnValue($code)); $result = $this->model->compareOptions([$code => $optionsOneMock], ['someOneElse' => $optionsTwoMock]); $this->assertFalse($result); }
public function testGetProduct() { $productId = 1; $storeId = 0; $this->model->setData('product_id', $productId); $this->model->setData('store_id', $storeId); $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $productMock->expects($this->any())->method('setFinalPrice')->with(null); $productMock->expects($this->any())->method('setCustomOprtions')->with([]); $this->productRepository->expects($this->once())->method('getById')->willReturn($productMock); $this->assertEquals($productMock, $this->model->getProduct()); }
/** * Get all option for item * * @param Item|int|string $item * @return array */ public function getOptionsByItem($item) { if ($item instanceof Item) { $itemId = $item->getId(); } else { $itemId = $item; } $this->load(); $options = []; if (isset($this->_optionsByItem[$itemId])) { foreach ($this->_optionsByItem[$itemId] as $optionId) { $options[] = $this->_items[$optionId]; } } return $options; }
/** * Retrieve params for updating product in wishlist * * @param \Magento\Catalog\Model\Product|\Magento\Wishlist\Model\Item $item * * @return string|false */ public function getUpdateParams($item) { $itemId = null; if ($item instanceof \Magento\Catalog\Model\Product) { $itemId = $item->getWishlistItemId(); $productId = $item->getId(); } if ($item instanceof \Magento\Wishlist\Model\Item) { $itemId = $item->getId(); $productId = $item->getProduct()->getId(); } $url = $this->_getUrl('wishlist/index/updateItemOptions'); if ($itemId) { $params = array('id' => $itemId, 'product' => $productId); return $this->_postDataHelper->getPostData($url, $params); } return false; }
/** * Returns html for showing item options * * @param \Magento\Wishlist\Model\Item $item * @return string * * @deprecated after 1.6.2.0 */ public function getDetailsHtml(\Magento\Wishlist\Model\Item $item) { $cfg = $this->getOptionsRenderCfg($item->getProduct()->getTypeId()); if (!$cfg) { return ''; } $block = $this->getChildBlock('item_options'); if (!$block) { return ''; } if ($cfg['template']) { $template = $cfg['template']; } else { $cfgDefault = $this->getOptionsRenderCfg('default'); if (!$cfgDefault) { return ''; } $template = $cfgDefault['template']; } $block->setTemplate($template); $block->setOptionList($this->_helperPool->get($cfg['helper'])->getOptions($item)); return $block->toHtml(); }
/** * Retrieve Qty from item * * @param \Magento\Wishlist\Model\Item|\Magento\Catalog\Model\Product $item * @return float */ public function getQty($item) { $qty = $item->getQty() * 1; if (!$qty) { $qty = 1; } return $qty; }
/** * Retrieve URL to item Product * * @param \Magento\Wishlist\Model\Item|\Magento\Catalog\Model\Product $item * @param array $additional * @return string */ public function getProductUrl($item, $additional = []) { if ($item instanceof \Magento\Catalog\Model\Product) { $product = $item; } else { $product = $item->getProduct(); } $buyRequest = $item->getBuyRequest(); if (is_object($buyRequest)) { $config = $buyRequest->getSuperProductConfig(); if ($config && !empty($config['product_id'])) { $product = $this->productRepository->getById($config['product_id'], false, $this->_storeManager->getStore()->getStoreId()); } } return $product->getUrlModel()->getUrl($product, $additional); }
/** * Retrieve product identifier linked with item * * @param \Magento\Wishlist\Model\Item $item * @return int */ public function getProductId($item) { return $item->getProduct()->getId(); }
/** * Adding item to wishlist * * @param Item $item * @return $this */ public function addItem(Item $item) { $item->setWishlist($this); if (!$item->getId()) { $this->getItemCollection()->addItem($item); $this->_eventManager->dispatch('wishlist_add_item', array('item' => $item)); } return $this; }
/** * Retrieve wishlist item data * * @param \Magento\Wishlist\Model\Item $wishlistItem * @return array */ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem) { $product = $wishlistItem->getProduct(); return ['image' => $this->getImageData($product), '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, true), 'delete_item_params' => $this->wishlistHelper->getRemoveParams($wishlistItem, true)]; }
/** * Set quote item * * @param Item $item * @return $this */ public function setItem($item) { $this->setWishlistItemId($item->getId()); $this->_item = $item; return $this; }
/** * Retrieve URL to item Product * * @param \Magento\Wishlist\Model\Item|\Magento\Catalog\Model\Product $item * @param array $additional * @return string */ public function getProductUrl($item, $additional = array()) { if ($item instanceof \Magento\Catalog\Model\Product) { $product = $item; } else { $product = $item->getProduct(); } $buyRequest = $item->getBuyRequest(); if (is_object($buyRequest)) { $config = $buyRequest->getSuperProductConfig(); if ($config && !empty($config['product_id'])) { $product = $this->_productFactory->create()->setStoreId($this->_storeManager->getStore()->getStoreId())->load($config['product_id']); } } return parent::getProductUrl($product, $additional); }
/** * Returns qty to show visually to user * * @param \Magento\Wishlist\Model\Item $item * @return float */ public function getAddToCartQty(\Magento\Wishlist\Model\Item $item) { $qty = $item->getQty(); return $qty ? $qty : 1; }