Example #1
0
 /**
  * Load Wysiwyg on demand and prepare layout
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     if ($this->_catalogData->isModuleEnabled('Magento_Cms') && $this->_wysiwygConfig->isEnabled()) {
         $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
     }
 }
Example #2
0
 /**
  * Redefine Attribute scope
  *
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return $this
  */
 public function setScope($attribute)
 {
     if ($this->_helper->isPriceGlobal()) {
         $attribute->setIsGlobal(ScopedAttributeInterface::SCOPE_GLOBAL);
     } else {
         $attribute->setIsGlobal(ScopedAttributeInterface::SCOPE_WEBSITE);
     }
     return $this;
 }
Example #3
0
 /**
  * Redefine Attribute scope
  *
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @return $this
  */
 public function setScope($attribute)
 {
     if ($this->_helper->isPriceGlobal()) {
         $attribute->setIsGlobal(\Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL);
     } else {
         $attribute->setIsGlobal(\Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE);
     }
     return $this;
 }
Example #4
0
 /**
  * Processing object before save data
  *
  * @return $this
  */
 public function afterSave()
 {
     if (!$this->_catalogData->isPriceGlobal() && $this->getWebsiteId()) {
         $this->getResource()->saveSelectionPrice($this);
         if (!$this->getDefaultPriceScope()) {
             $this->unsSelectionPriceValue();
             $this->unsSelectionPriceType();
         }
     }
     parent::afterSave();
 }
Example #5
0
 /**
  * @return Grid
  */
 protected function _prepareCollection()
 {
     $productId = $this->getRequest()->getParam('id');
     $websiteId = 0;
     if ($store = $this->getRequest()->getParam('store')) {
         $websiteId = $this->_storeManager->getStore($store)->getWebsiteId();
     }
     if ($this->_catalogData->isModuleEnabled('Magento_ProductAlert')) {
         $collection = $this->_priceFactory->create()->getCustomerCollection()->join($productId, $websiteId);
         $this->setCollection($collection);
     }
     return parent::_prepareCollection();
 }
 protected function setUp()
 {
     $this->_helper = $this->getMock('Magento\\Catalog\\Helper\\Data', array('isPriceGlobal'), array(), '', false);
     $this->_helper->expects($this->any())->method('isPriceGlobal')->will($this->returnValue(true));
     $loggerMock = $this->getMock('Magento\\Framework\\Logger', array(), array(), '', false);
     $currencyFactoryMock = $this->getMock('Magento\\Directory\\Model\\CurrencyFactory', array(), array(), '', false);
     $storeManagerMock = $this->getMock('Magento\\Framework\\StoreManagerInterface', array(), array(), '', false);
     $productTypeMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Type', array(), array(), '', false);
     $configMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->_model = $this->getMockForAbstractClass('Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Groupprice\\AbstractGroupprice', array('logger' => $loggerMock, 'currencyFactory' => $currencyFactoryMock, 'storeManager' => $storeManagerMock, 'catalogData' => $this->_helper, 'config' => $configMock, 'catalogProductType' => $productTypeMock));
     $resource = $this->getMock('StdClass', array('getMainTable'));
     $resource->expects($this->any())->method('getMainTable')->will($this->returnValue('table'));
     $this->_model->expects($this->any())->method('_getResource')->will($this->returnValue($resource));
 }
 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $productTable = $this->resource->getTableName('catalog_product_entity');
     $priceSelect = $this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $this->resource->getTableName('catalog_product_entity_tier_price')], "t.{$linkField} = child.{$linkField}", [])->where('parent.entity_id = ? ', $productId)->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('t.qty = ?', 1)->order('t.value ' . Select::SQL_ASC)->limit(1);
     $priceSelectDefault = clone $priceSelect;
     $priceSelectDefault->where('t.website_id = ?', self::DEFAULT_WEBSITE_ID);
     $select[] = $priceSelectDefault;
     if (!$this->catalogHelper->isPriceGlobal()) {
         $priceSelect->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId());
         $select[] = $priceSelect;
     }
     return $select;
 }
Example #8
0
 /**
  * Preparing layout
  *
  * @return \Magento\Catalog\Block\Breadcrumbs
  */
 protected function _prepareLayout()
 {
     if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
         $breadcrumbsBlock->addCrumb('home', ['label' => __('Home'), 'title' => __('Go to Home Page'), 'link' => $this->_storeManager->getStore()->getBaseUrl()]);
         $title = [];
         $path = $this->_catalogData->getBreadcrumbPath();
         foreach ($path as $name => $breadcrumb) {
             $breadcrumbsBlock->addCrumb($name, $breadcrumb);
             $title[] = $breadcrumb['label'];
         }
         $this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title)));
     }
     return parent::_prepareLayout();
 }
 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
     $productTable = $this->resource->getTableName('catalog_product_entity');
     $priceSelect = $this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $priceAttribute->getBackendTable()], "t.{$linkField} = child.{$linkField}", [])->where('parent.entity_id = ? ', $productId)->where('t.attribute_id = ?', $priceAttribute->getAttributeId())->where('t.value IS NOT NULL')->order('t.value ' . Select::SQL_ASC)->limit(1);
     $priceSelectDefault = clone $priceSelect;
     $priceSelectDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
     $select[] = $priceSelectDefault;
     if (!$this->catalogHelper->isPriceGlobal()) {
         $priceSelect->where('t.store_id = ?', $this->storeManager->getStore()->getId());
         $select[] = $priceSelect;
     }
     return $select;
 }
 /**
  * Set Quote information about MSRP price enabled
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var $quote \Magento\Sales\Model\Quote */
     $quote = $observer->getEvent()->getQuote();
     $canApplyMsrp = false;
     if ($this->catalogData->isMsrpEnabled()) {
         foreach ($quote->getAllAddresses() as $address) {
             if ($address->getCanApplyMsrp()) {
                 $canApplyMsrp = true;
                 break;
             }
         }
     }
     $quote->setCanApplyMsrp($canApplyMsrp);
 }
Example #11
0
 /**
  * Check if can apply msrp to totals
  *
  * @return bool
  */
 public function canApplyMsrp()
 {
     if (!$this->getQuote()->hasCanApplyMsrp() && $this->_catalogData->isMsrpEnabled()) {
         $this->getQuote()->collectTotals();
     }
     return $this->getQuote()->getCanApplyMsrp();
 }
Example #12
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getItems()
 {
     Profiler::start(__METHOD__);
     $items = [];
     /** @var \Magento\Catalog\Model\Product $product */
     foreach ($this->collection as $product) {
         $item = ['sku' => $product->getSku(), 'name' => $product->getName(), 'url' => $product->getProductUrl(), 'description' => null, 'image' => null, 'price' => null, 'rating' => null];
         if ($this->config->isShowShortDescription()) {
             $item['description'] = html_entity_decode(strip_tags($product->getDataUsingMethod('description')));
         }
         $image = false;
         if ($product->getImage() && $product->getImage() != 'no_selection') {
             $image = $product->getImage();
         } elseif ($product->getSmallImage() && $product->getSmallImage() != 'no_selection') {
             $image = $product->getSmallImage();
         }
         if ($this->config->isShowImage() && $image) {
             $item['image'] = $this->imageHelper->init($product, false)->setImageFile($image)->resize(65 * 2, 80 * 2)->getUrl();
         }
         if ($this->config->isShowPrice()) {
             $item['price'] = $this->catalogHelper->getTaxPrice($product, $product->getFinalPrice());
             $item['price'] = $this->pricingHelper->currency($item['price'], false, false);
         }
         if ($this->config->isShowRating()) {
             $item['rating'] = $this->reviewRenderer->getReviewsSummaryHtml($product, ReviewRendererInterface::SHORT_VIEW);
         }
         $items[] = $item;
     }
     Profiler::stop(__METHOD__);
     return $items;
 }
Example #13
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetSelectionsByIds()
 {
     $selectionIds = [1, 2, 3];
     $usedSelectionsIds = [4, 5, 6];
     $storeId = 2;
     $websiteId = 1;
     $storeFilter = 'store_filter';
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $usedSelectionsMock = $this->getMockBuilder('Magento\\Bundle\\Model\\Resource\\Selection\\Collection')->setMethods(['addAttributeToSelect', 'setFlag', 'addStoreFilter', 'setStoreId', 'setPositionOrder', 'addFilterByRequiredOptions', 'setSelectionIdsFilter', 'joinPrices'])->disableOriginalConstructor()->getMock();
     $productGetMap = [['_cache_instance_used_selections', null, null], ['_cache_instance_used_selections_ids', null, $usedSelectionsIds], ['_cache_instance_store_filter', null, $storeFilter]];
     $productMock->expects($this->any())->method('getData')->will($this->returnValueMap($productGetMap));
     $productSetMap = [['_cache_instance_used_selections', $usedSelectionsMock, $productMock], ['_cache_instance_used_selections_ids', $selectionIds, $productMock]];
     $productMock->expects($this->any())->method('setData')->will($this->returnValueMap($productSetMap));
     $productMock->expects($this->once())->method('getStoreId')->will($this->returnValue($storeId));
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getWebsiteId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($storeMock));
     $storeMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $this->bundleCollection->expects($this->once())->method('create')->will($this->returnValue($usedSelectionsMock));
     $usedSelectionsMock->expects($this->once())->method('addAttributeToSelect')->with('*')->will($this->returnSelf());
     $flagMap = [['require_stock_items', true, $usedSelectionsMock], ['product_children', true, $usedSelectionsMock]];
     $usedSelectionsMock->expects($this->any())->method('setFlag')->will($this->returnValueMap($flagMap));
     $usedSelectionsMock->expects($this->once())->method('addStoreFilter')->with($storeFilter)->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('setPositionOrder')->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('addFilterByRequiredOptions')->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('setSelectionIdsFilter')->with($selectionIds)->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('joinPrices')->with($websiteId)->will($this->returnSelf());
     $this->catalogData->expects($this->once())->method('isPriceGlobal')->will($this->returnValue(false));
     $this->model->getSelectionsByIds($selectionIds, $productMock);
 }
Example #14
0
 /**
  * Disable MAP if it's bundle with dynamic price type
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 public function beforeSave($product)
 {
     if (!$product instanceof \Magento\Catalog\Model\Product || $product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE || $product->getPriceType() != \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
         return parent::beforeSave($product);
     }
     parent::beforeSave($product);
     $attributeCode = $this->getAttribute()->getName();
     $value = $product->getData($attributeCode);
     if (empty($value)) {
         $value = $this->_catalogData->isMsrpApplyToAll();
     }
     if ($value) {
         $product->setData($attributeCode, 0);
     }
     return $this;
 }
Example #15
0
 protected function setUp()
 {
     $this->_helper = $this->getMock('Magento\\Catalog\\Helper\\Data', ['isPriceGlobal'], [], '', false);
     $this->_helper->expects($this->any())->method('isPriceGlobal')->will($this->returnValue(true));
     $currencyFactoryMock = $this->getMock('Magento\\Directory\\Model\\CurrencyFactory', ['create'], [], '', false);
     $storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false);
     $productTypeMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Type', [], [], '', false);
     $configMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $localeFormatMock = $this->getMock('\\Magento\\Framework\\Locale\\FormatInterface', [], [], '', false);
     $groupManagement = $this->getMock('Magento\\Customer\\Api\\GroupManagementInterface', [], [], '', false);
     $metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->_model = $this->getMockForAbstractClass('Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\GroupPrice\\AbstractGroupPrice', ['currencyFactory' => $currencyFactoryMock, 'storeManager' => $storeManagerMock, 'catalogData' => $this->_helper, 'config' => $configMock, 'localeFormat' => $localeFormatMock, 'catalogProductType' => $productTypeMock, 'groupManagement' => $groupManagement, 'metadataPool' => $metadataPool]);
     $resource = $this->getMock('StdClass', ['getMainTable']);
     $resource->expects($this->any())->method('getMainTable')->will($this->returnValue('table'));
     $this->_model->expects($this->any())->method('_getResource')->will($this->returnValue($resource));
 }
Example #16
0
 /**
  * Retrieve stock option array
  *
  * @return array
  */
 public function getStockOption()
 {
     if ($this->catalogData->isModuleEnabled('Magento_CatalogInventory')) {
         return $this->stock->toOptionArray();
     }
     return array();
 }
Example #17
0
 /**
  * @return $this
  */
 protected function _prepareColumns()
 {
     $this->addColumn('entity_id', array('header' => __('ID'), 'type' => 'number', 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id'));
     $this->addColumn('name', array('header' => __('Name'), 'index' => 'name', 'class' => 'xxx'));
     $store = $this->_getStore();
     if ($store->getId()) {
         $this->addColumn('custom_name', array('header' => __('Name in %1', $store->getName()), 'index' => 'custom_name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name'));
     }
     $this->addColumn('type', array('header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray()));
     $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash();
     $this->addColumn('set_name', array('header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name'));
     $this->addColumn('sku', array('header' => __('SKU'), 'index' => 'sku'));
     $store = $this->_getStore();
     $this->addColumn('price', array('header' => __('Price'), 'type' => 'price', 'currency_code' => $store->getBaseCurrency()->getCode(), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price'));
     if ($this->_catalogData->isModuleEnabled('Magento_CatalogInventory')) {
         $this->addColumn('qty', array('header' => __('Quantity'), 'type' => 'number', 'index' => 'qty'));
     }
     $this->addColumn('visibility', array('header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility'));
     $this->addColumn('status', array('header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray()));
     if (!$this->_storeManager->isSingleStoreMode()) {
         $this->addColumn('websites', array('header' => __('Websites'), 'sortable' => false, 'index' => 'websites', 'type' => 'options', 'options' => $this->_websiteFactory->create()->getCollection()->toOptionHash(), 'header_css_class' => 'col-websites', 'column_css_class' => 'col-websites'));
     }
     $this->addColumn('edit', array('header' => __('Edit'), 'type' => 'action', 'getter' => 'getId', 'actions' => array(array('caption' => __('Edit'), 'url' => array('base' => '*/*/edit', 'params' => array('store' => $this->getRequest()->getParam('store'))), 'field' => 'id')), 'filter' => false, 'sortable' => false, 'index' => 'stores', 'header_css_class' => 'col-action', 'column_css_class' => 'col-action'));
     if ($this->_catalogData->isModuleEnabled('Magento_Rss')) {
         $this->addRssList('rss/catalog/notifystock', __('Notify Low Stock RSS'));
     }
     return parent::_prepareColumns();
 }
Example #18
0
 /**
  * Collect information about MSRP price enabled
  *
  * @param  \Magento\Sales\Model\Quote\Address $address
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Quote\Address $address)
 {
     parent::collect($address);
     $items = $this->_getAddressItems($address);
     if (!count($items)) {
         return $this;
     }
     $canApplyMsrp = false;
     foreach ($items as $item) {
         if (!$item->getParentItemId() && $this->_catalogData->canApplyMsrp($item->getProductId(), \Magento\Catalog\Model\Product\Attribute\Source\Msrp\Type::TYPE_BEFORE_ORDER_CONFIRM, true)) {
             $canApplyMsrp = true;
             break;
         }
     }
     $address->setCanApplyMsrp($canApplyMsrp);
     return $this;
 }
Example #19
0
 /**
  * Save title and price of link item
  *
  * @param \Magento\Downloadable\Model\Link $linkObject
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function saveItemTitleAndPrice($linkObject)
 {
     $connection = $this->getConnection();
     $linkTitleTable = $this->getTable('downloadable_link_title');
     $linkPriceTable = $this->getTable('downloadable_link_price');
     $select = $connection->select()->from($this->getTable('downloadable_link_title'))->where('link_id=:link_id AND store_id=:store_id');
     $bind = [':link_id' => $linkObject->getId(), ':store_id' => (int) $linkObject->getStoreId()];
     if ($connection->fetchOne($select, $bind)) {
         $where = ['link_id = ?' => $linkObject->getId(), 'store_id = ?' => (int) $linkObject->getStoreId()];
         if ($linkObject->getUseDefaultTitle()) {
             $connection->delete($linkTitleTable, $where);
         } else {
             $insertData = ['title' => $linkObject->getTitle()];
             $connection->update($linkTitleTable, $insertData, $where);
         }
     } else {
         if (!$linkObject->getUseDefaultTitle()) {
             $connection->insert($linkTitleTable, ['link_id' => $linkObject->getId(), 'store_id' => (int) $linkObject->getStoreId(), 'title' => $linkObject->getTitle()]);
         }
     }
     $select = $connection->select()->from($linkPriceTable)->where('link_id=:link_id AND website_id=:website_id');
     $bind = [':link_id' => $linkObject->getId(), ':website_id' => (int) $linkObject->getWebsiteId()];
     if ($connection->fetchOne($select, $bind)) {
         $where = ['link_id = ?' => $linkObject->getId(), 'website_id = ?' => $linkObject->getWebsiteId()];
         if ($linkObject->getUseDefaultPrice()) {
             $connection->delete($linkPriceTable, $where);
         } else {
             $connection->update($linkPriceTable, ['price' => $linkObject->getPrice()], $where);
         }
     } else {
         if (!$linkObject->getUseDefaultPrice()) {
             $dataToInsert[] = ['link_id' => $linkObject->getId(), 'website_id' => (int) $linkObject->getWebsiteId(), 'price' => (double) $linkObject->getPrice()];
             if ($linkObject->getOrigData('link_id') != $linkObject->getLinkId()) {
                 $_isNew = true;
             } else {
                 $_isNew = false;
             }
             if ($linkObject->getWebsiteId() == 0 && $_isNew && !$this->_catalogData->isPriceGlobal()) {
                 $websiteIds = $linkObject->getProductWebsiteIds();
                 foreach ($websiteIds as $websiteId) {
                     $baseCurrency = $this->_configuration->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, 'default');
                     $websiteCurrency = $this->_storeManager->getWebsite($websiteId)->getBaseCurrencyCode();
                     if ($websiteCurrency == $baseCurrency) {
                         continue;
                     }
                     $rate = $this->_createCurrency()->load($baseCurrency)->getRate($websiteCurrency);
                     if (!$rate) {
                         $rate = 1;
                     }
                     $newPrice = $linkObject->getPrice() * $rate;
                     $dataToInsert[] = ['link_id' => $linkObject->getId(), 'website_id' => (int) $websiteId, 'price' => $newPrice];
                 }
             }
             $connection->insertMultiple($linkPriceTable, $dataToInsert);
         }
     }
     return $this;
 }
 /**
  * Get price with including/excluding tax
  *
  * @param float $price
  * @param bool $includingTax
  * @return float
  */
 public function getPrice($price, $includingTax = null)
 {
     if ($includingTax !== null) {
         $price = $this->_catalogHelper->getTaxPrice($this->getProduct(), $price, true);
     } else {
         $price = $this->_catalogHelper->getTaxPrice($this->getProduct(), $price);
     }
     return $price;
 }
 public function testSavePrices()
 {
     $rowSet = [0 => ['value_id' => '1', 'product_super_attribute_id' => '1', 'value_index' => '12', 'is_percent' => '0', 'pricing_value' => '3.0000', 'website_id' => '0'], 1 => ['value_id' => '2', 'product_super_attribute_id' => '1', 'value_index' => '13', 'is_percent' => '0', 'pricing_value' => '8.0000', 'website_id' => '0']];
     $values = [12 => ['value_index' => '12', 'pricing_value' => '', 'is_percent' => '0', 'include' => '1'], 13 => ['value_index' => '13', 'pricing_value' => '5', 'is_percent' => '0', 'include' => '1'], 14 => ['value_index' => '14', 'pricing_value' => '3', 'is_percent' => '0', 'include' => '1']];
     $attribute = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->setMethods(['getValues', 'getId'])->disableOriginalConstructor()->getMock();
     $adapterMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock();
     $selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->resource->expects($this->once())->method('getConnection')->with('core_write')->willReturn($adapterMock);
     $this->catalogData->expects($this->any())->method('isPriceGlobal')->willReturn(1);
     $attribute->expects($this->once())->method('getValues')->willReturn($values);
     $adapterMock->expects($this->once())->method('select')->willReturn($selectMock);
     $selectMock->expects($this->once())->method('from')->with(null)->will($this->returnSelf());
     $selectMock->expects($this->at(1))->method('where')->with('product_super_attribute_id = :product_super_attribute_id')->will($this->returnSelf());
     $selectMock->expects($this->at(2))->method('where')->with('website_id = :website_id')->will($this->returnSelf());
     $attribute->expects($this->any())->method('getId')->willReturn(1);
     $adapterMock->expects($this->once())->method('fetchAll')->with($selectMock, ['product_super_attribute_id' => 1, 'website_id' => 0])->willReturn($rowSet);
     $this->assertEquals($this->model, $this->model->savePrices($attribute));
 }
Example #22
0
 /**
  * Load prices for configurable attribute
  *
  * @param ConfigurableAttribute $object
  * @return $this
  */
 protected function loadPrices(ConfigurableAttribute $object)
 {
     $websiteId = $this->_catalogData->isPriceGlobal() ? 0 : (int) $this->_storeManager->getStore()->getWebsiteId();
     $select = $this->_getReadAdapter()->select()->from($this->_priceTable)->where('product_super_attribute_id = ?', $object->getId())->where('website_id = ?', $websiteId);
     foreach ($select->query() as $row) {
         $data = ['value_index' => $row['value_index'], 'is_percent' => $row['is_percent'], 'pricing_value' => $row['pricing_value']];
         $object->addPrice($data);
     }
     return $this;
 }
Example #23
0
 /**
  * Returns product price block html
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param boolean $displayMinimalPrice
  * @param string $idSuffix
  * @return string
  * @deprecated
  */
 public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix = '')
 {
     $typeId = $product->getTypeId();
     if ($this->_catalogData->canApplyMsrp($product)) {
         $realPriceHtml = $this->_preparePriceRenderer($typeId)->setProduct($product)->setDisplayMinimalPrice($displayMinimalPrice)->setIdSuffix($idSuffix)->toHtml();
         $product->setAddToCartUrl($this->getAddToCartUrl($product));
         $product->setRealPriceHtml($realPriceHtml);
         $typeId = $this->_mapRenderer;
     }
     return $this->_preparePriceRenderer($typeId)->setProduct($product)->setDisplayMinimalPrice($displayMinimalPrice)->setIdSuffix($idSuffix)->toHtml();
 }
Example #24
0
 /**
  * Get price configuration
  *
  * @param \Magento\Catalog\Model\Product\Option\Value|\Magento\Catalog\Model\Product\Option $option
  * @return array
  */
 protected function _getPriceConfiguration($option)
 {
     $data = array();
     $data['price'] = $this->_coreData->currency($option->getPrice(true), false, false);
     $data['oldPrice'] = $this->_coreData->currency($option->getPrice(false), false, false);
     $data['priceValue'] = $option->getPrice(false);
     $data['type'] = $option->getPriceType();
     $data['exclTaxPrice'] = $price = $this->_catalogData->getTaxPrice($option->getProduct(), $data['price'], false);
     $data['inclTaxPrice'] = $price = $this->_catalogData->getTaxPrice($option->getProduct(), $data['price'], true);
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $connection = $this->resource->getConnection();
     $specialPriceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'special_price');
     $specialPriceFromDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_from_date');
     $specialPriceToDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_to_date');
     $timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
     $currentDate = $this->dateTime->formatDate($timestamp, false);
     $productTable = $this->resource->getTableName('catalog_product_entity');
     $specialPrice = $this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $specialPriceAttribute->getBackendTable()], "t.{$linkField} = child.{$linkField}", [])->joinLeft(['special_from' => $specialPriceFromDate->getBackendTable()], $connection->quoteInto("t.{$linkField} = special_from.{$linkField} AND special_from.attribute_id = ?", $specialPriceFromDate->getAttributeId()), '')->joinLeft(['special_to' => $specialPriceToDate->getBackendTable()], $connection->quoteInto("t.{$linkField} = special_to.{$linkField} AND special_to.attribute_id = ?", $specialPriceToDate->getAttributeId()), '')->where('parent.entity_id = ? ', $productId)->where('t.attribute_id = ?', $specialPriceAttribute->getAttributeId())->where('t.value IS NOT NULL')->where('special_from.value IS NULL OR ' . $connection->getDatePartSql('special_from.value') . ' <= ?', $currentDate)->where('special_to.value IS NULL OR ' . $connection->getDatePartSql('special_to.value') . ' >= ?', $currentDate)->order('t.value ' . Select::SQL_ASC)->limit(1);
     $specialPriceDefault = clone $specialPrice;
     $specialPriceDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
     $select[] = $specialPriceDefault;
     if (!$this->catalogHelper->isPriceGlobal()) {
         $specialPrice->where('t.store_id = ?', $this->storeManager->getStore()->getId());
         $select[] = $specialPrice;
     }
     return $select;
 }
 /**
  * Additional function to break up mocks initialization
  *
  * @return void
  */
 protected function addMocks()
 {
     $resIteratorcallback = function () {
         $arguments = func_get_args();
         $arguments[2]['results'] = [['use_special' => false, 'price' => 10, 'final_price' => 20]];
     };
     $this->storeMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue(0));
     $this->storeMock->expects($this->once())->method('getFrontendName')->will($this->returnValue('store name'));
     $this->catalogHelperMock->expects($this->once())->method('canApplyMsrp')->will($this->returnValue(false));
     $this->resourceIteratorMock->expects($this->once())->method('walk')->will($this->returnCallback($resIteratorcallback));
     $this->imageHelperMock->expects($this->once())->method('init')->will($this->returnSelf());
 }
Example #27
0
 /**
  * @return string
  */
 public function getElementHtml()
 {
     /** @var \Magento\Framework\Data\Form\Element\AbstractElement $element */
     $element = $this->getElement();
     if (!$element->getValue()) {
         return parent::getElementHtml();
     }
     $element->setOnkeyup("onUrlkeyChanged('" . $element->getHtmlId() . "')");
     $element->setOnchange("onUrlkeyChanged('" . $element->getHtmlId() . "')");
     $data = array('name' => $element->getData('name') . '_create_redirect', 'disabled' => true);
     /** @var \Magento\Framework\Data\Form\Element\Hidden $hidden */
     $hidden = $this->_elementFactory->create('hidden', array('data' => $data));
     $hidden->setForm($element->getForm());
     $storeId = $element->getForm()->getDataObject()->getStoreId();
     $data['html_id'] = $element->getHtmlId() . '_create_redirect';
     $data['label'] = __('Create Permanent Redirect for old URL');
     $data['value'] = $element->getValue();
     $data['checked'] = $this->_catalogData->shouldSaveUrlRewritesHistory($storeId);
     /** @var \Magento\Framework\Data\Form\Element\Checkbox $checkbox */
     $checkbox = $this->_elementFactory->create('checkbox', array('data' => $data));
     $checkbox->setForm($element->getForm());
     return parent::getElementHtml() . '<br/>' . $hidden->getElementHtml() . $checkbox->getElementHtml() . $checkbox->getLabelHtml();
 }
Example #28
0
 /**
  * Prepare category attribute html output
  *
  * @param ModelCategory $category
  * @param string $attributeHtml
  * @param string $attributeName
  * @return string
  */
 public function categoryAttribute($category, $attributeHtml, $attributeName)
 {
     $attribute = $this->_eavConfig->getAttribute(ModelCategory::ENTITY, $attributeName);
     if ($attribute && $attribute->getFrontendInput() != 'image' && (!$attribute->getIsHtmlAllowedOnFront() && !$attribute->getIsWysiwygEnabled())) {
         $attributeHtml = $this->_escaper->escapeHtml($attributeHtml);
     }
     if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled()) {
         if ($this->_catalogData->isUrlDirectivesParsingAllowed()) {
             $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
         }
     }
     $attributeHtml = $this->process('categoryAttribute', $attributeHtml, ['category' => $category, 'attribute' => $attributeName]);
     return $attributeHtml;
 }
Example #29
0
 /**
  * @param \Magento\Framework\Object $input
  * @param float $expectOutputPrice
  * @param string[] $configs
  * @param string $productClassName
  *
  * @magentoDataFixture Magento/Catalog/_files/products.php
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_address.php
  * @magentoDbIsolation enabled
  * @dataProvider getTaxPriceDataProvider
  */
 public function testGetTaxPrice($input, $expectOutputPrice, $configs = [], $productClassName = 'DefaultProductClass')
 {
     $this->setUpDefaultRules();
     $fixtureProductId = 1;
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product')->load($fixtureProductId);
     $product->setTaxClassId($this->taxClasses[$productClassName]);
     $shippingAddress = $this->getCustomerAddress();
     $billingAddress = $shippingAddress;
     foreach ($configs as $config) {
         $this->scopeConfig->setValue($config['path'], $config['value'], ScopeInterface::SCOPE_STORE, 'default');
     }
     $price = $this->helper->getTaxPrice($product, $input->getPrice(), $input->getIncludingTax(), $shippingAddress, $billingAddress, $this->taxClasses['DefaultCustomerClass'], $input->getStore(), $input->getPriceIncludesTax(), $input->getRoundPrice());
     $this->assertEquals($expectOutputPrice, $price);
 }
Example #30
0
 /**
  * Retrieve bundle selections collection based on ids
  *
  * @param array $selectionIds
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Bundle\Model\ResourceModel\Selection\Collection
  */
 public function getSelectionsByIds($selectionIds, $product)
 {
     sort($selectionIds);
     $usedSelections = $product->getData($this->_keyUsedSelections);
     $usedSelectionsIds = $product->getData($this->_keyUsedSelectionsIds);
     if (!$usedSelections || $usedSelectionsIds !== $selectionIds) {
         $storeId = $product->getStoreId();
         $usedSelections = $this->_bundleCollection->create()->addAttributeToSelect('*')->setFlag('require_stock_items', true)->setFlag('product_children', true)->addStoreFilter($this->getStoreFilter($product))->setStoreId($storeId)->setPositionOrder()->addFilterByRequiredOptions()->setSelectionIdsFilter($selectionIds);
         if (!$this->_catalogData->isPriceGlobal() && $storeId) {
             $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
             $usedSelections->joinPrices($websiteId);
         }
         $product->setData($this->_keyUsedSelections, $usedSelections);
         $product->setData($this->_keyUsedSelectionsIds, $selectionIds);
     }
     return $usedSelections;
 }