/**
  * Generate product url rewrites
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 public function generate(Product $product)
 {
     $this->product = $product;
     $storeId = $this->product->getStoreId();
     $productCategories = $product->getCategoryCollection()->addAttributeToSelect('url_key')->addAttributeToSelect('url_path');
     $urls = $this->isGlobalScope($storeId) ? $this->generateForGlobalScope($productCategories) : $this->generateForSpecificStoreView($storeId, $productCategories);
     $this->product = null;
     return $urls;
 }
Example #2
0
 /**
  * @param Product $product
  * @param int $attributeId
  * @return array
  */
 public function loadProductGalleryByAttributeId($product, $attributeId)
 {
     $select = $this->createBaseLoadSelect($product->getId(), $product->getStoreId(), $attributeId);
     $result = $this->getConnection()->fetchAll($select);
     $this->_removeDuplicates($result);
     return $result;
 }
Example #3
0
 /**
  * @param \Magento\Catalog\Model\Product $productModel
  * @return \Ess\M2ePro\Model\Magento\Product
  */
 public function setProduct(\Magento\Catalog\Model\Product $productModel)
 {
     $this->_productModel = $productModel;
     $this->setProductId($this->_productModel->getId());
     $this->setStoreId($this->_productModel->getStoreId());
     return $this;
 }
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $targetCountry = $this->_config->getTargetCountry($product->getStoreId());
     $value = $this->_typeFactory->create()->loadByAttributeSetId($product->getAttributeSetId(), $targetCountry);
     $val = $value->getCategory() == \Magento\GoogleShopping\Helper\Category::CATEGORY_OTHER ? '' : $value->getCategory();
     $this->_setAttribute($entry, 'google_product_category', self::ATTRIBUTE_TYPE_TEXT, htmlspecialchars_decode($val, ENT_NOQUOTES));
     return $entry;
 }
 public function testGetStoreId()
 {
     $this->model->setStoreId(3);
     $this->assertEquals(3, $this->model->getStoreId());
     $this->model->unsStoreId();
     $this->store->expects($this->once())->method('getId')->will($this->returnValue(5));
     $this->assertEquals(5, $this->model->getStoreId());
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function generate($product)
 {
     $this->product = $product;
     $storeId = $this->product->getStoreId();
     $urls = $this->catalogUrlRewriteHelper->isDefaultStore($storeId) ? $this->generateForDefaultStore() : $this->generateForStore($storeId);
     $this->product = null;
     $this->categories = null;
     return $urls;
 }
Example #7
0
 /**
  * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product
  * @param array $modelData
  * @return \Magento\Downloadable\Model\Sample|\PHPUnit_Framework_MockObject_MockObject
  */
 private function createSampleModel($product, array $modelData)
 {
     $sample = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Sample')->disableOriginalConstructor()->setMethods(['setData', 'setSampleType', 'setProductId', 'setStoreId', 'setProductWebsiteIds', 'setNumberOfDownloads', 'setSampleUrl', 'setLinkFile', 'setSampleFile', 'save'])->getMock();
     $sample->expects($this->once())->method('setData')->with($modelData)->will($this->returnSelf());
     $sample->expects($this->once())->method('setSampleType')->with($modelData['type'])->will($this->returnSelf());
     $sample->expects($this->once())->method('setProductId')->with($product->getId())->will($this->returnSelf());
     $sample->expects($this->once())->method('setStoreId')->with($product->getStoreId())->will($this->returnSelf());
     return $sample;
 }
Example #8
0
 /**
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @dataProvider convertAttributeDataProvider
  */
 public function testConvertAttribute($product, $entry)
 {
     /** @var \Magento\GoogleShopping\Model\Attribute\Price $model */
     $model = Bootstrap::getObjectManager()->create('Magento\\GoogleShopping\\Model\\Attribute\\Price');
     $groupManagement = Bootstrap::getObjectManager()->get('Magento\\Customer\\Api\\GroupManagementInterface');
     $defaultCustomerGroup = $groupManagement->getDefaultGroup($product->getStoreId());
     $model->convertAttribute($product, $entry);
     $this->assertEquals($defaultCustomerGroup->getId(), $product->getCustomerGroupId());
 }
 /**
  * {@inheritdoc}
  */
 public function getStoreId()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getStoreId');
     if (!$pluginInfo) {
         return parent::getStoreId();
     } else {
         return $this->___callPlugins('getStoreId', func_get_args(), $pluginInfo);
     }
 }
Example #10
0
 /**
  * The only rewritten line in this method is the return statement
  */
 public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
 {
     $routePath = '';
     $routeParams = $params;
     $storeId = $product->getStoreId();
     $categoryId = null;
     if (!isset($params['_ignore_category']) && $product->getCategoryId() && !$product->getDoNotUseCategoryId()) {
         $categoryId = $product->getCategoryId();
     }
     if ($product->hasUrlDataObject()) {
         $requestPath = $product->getUrlDataObject()->getUrlRewrite();
         $routeParams['_scope'] = $product->getUrlDataObject()->getStoreId();
     } else {
         $requestPath = $product->getRequestPath();
         if (empty($requestPath) && $requestPath !== false) {
             $filterData = [UrlRewrite::ENTITY_ID => $product->getId(), UrlRewrite::ENTITY_TYPE => \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE, UrlRewrite::STORE_ID => $storeId];
             if ($categoryId) {
                 $filterData[UrlRewrite::METADATA]['category_id'] = $categoryId;
             }
             $rewrite = $this->urlFinder->findOneByData($filterData);
             if ($rewrite) {
                 $requestPath = $rewrite->getRequestPath();
                 $product->setRequestPath($requestPath);
             } else {
                 $product->setRequestPath(false);
             }
         }
     }
     if (isset($routeParams['_scope'])) {
         $storeId = $this->storeManager->getStore($routeParams['_scope'])->getId();
     }
     if ($storeId != $this->storeManager->getStore()->getId()) {
         $routeParams['_scope_to_url'] = true;
     }
     if (!empty($requestPath)) {
         $routeParams['_direct'] = $requestPath;
     } else {
         $routePath = 'catalog/product/view';
         $routeParams['id'] = $product->getId();
         $routeParams['s'] = $product->getUrlKey();
         if ($categoryId) {
             $routeParams['category'] = $categoryId;
         }
     }
     // reset cached URL instance GET query params
     if (!isset($routeParams['_query'])) {
         $routeParams['_query'] = [];
     }
     /*
      * This is the only line changed from the default method.
      * For reference, the original line: $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
      * getUrlInstance() is a private method, so a new method has been written that will create a frontend Url object if
      * the store scope is not the admin scope.
      */
     return $this->getStoreScopeUrlInstance($storeId)->getUrl($routePath, $routeParams);
 }
Example #11
0
 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return array
  */
 protected function extractStoreIds($product)
 {
     $storeIds = $product->getStoreIds();
     $storeIds[] = \Magento\Store\Model\Store::DEFAULT_STORE_ID;
     // Removing current storeId.
     $storeIds = array_flip($storeIds);
     unset($storeIds[$product->getStoreId()]);
     $storeIds = array_keys($storeIds);
     return $storeIds;
 }
Example #12
0
 /**
  * Load gallery images for product
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Catalog\Model\Product\Attribute\Backend\Media $object
  * @return array
  */
 public function loadGallery($product, $object)
 {
     $adapter = $this->_getReadAdapter();
     $positionCheckSql = $adapter->getCheckSql('value.position IS NULL', 'default_value.position', 'value.position');
     // Select gallery images for product
     $select = $adapter->select()->from(array('main' => $this->getMainTable()), array('value_id', 'value AS file'))->joinLeft(array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), $adapter->quoteInto('main.value_id = value.value_id AND value.store_id = ?', (int) $product->getStoreId()), array('label', 'position', 'disabled'))->joinLeft(array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id = default_value.value_id AND default_value.store_id = 0', array('label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled'))->where('main.attribute_id = ?', $object->getAttribute()->getId())->where('main.entity_id = ?', $product->getId())->order($positionCheckSql . ' ' . \Magento\Framework\DB\Select::SQL_ASC);
     $result = $adapter->fetchAll($select);
     $this->_removeDuplicates($result);
     return $result;
 }
 /**
  * @param bool $isChangedUrlKey
  * @param bool $isChangedVisibility
  * @param bool $isChangedWebsites
  * @param bool $isChangedCategories
  * @param bool $visibilityResult
  * @param int $expectedDeleteCount
  * @param int $expectedReplaceCount
  *
  * @dataProvider testUrlKeyDataProvider
  */
 public function testExecuteUrlKey($isChangedUrlKey, $isChangedVisibility, $isChangedWebsites, $isChangedCategories, $visibilityResult, $expectedDeleteCount, $expectedReplaceCount)
 {
     $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue(12));
     $this->product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValueMap([['visibility', $isChangedVisibility], ['url_key', $isChangedUrlKey]]));
     $this->product->expects($this->any())->method('getIsChangedWebsites')->will($this->returnValue($isChangedWebsites));
     $this->product->expects($this->any())->method('getIsChangedCategories')->will($this->returnValue($isChangedCategories));
     $this->urlPersist->expects($this->exactly($expectedDeleteCount))->method('deleteByData')->with([UrlRewrite::ENTITY_ID => $this->product->getId(), UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, UrlRewrite::REDIRECT_TYPE => 0, UrlRewrite::STORE_ID => $this->product->getStoreId()]);
     $this->product->expects($this->any())->method('isVisibleInSiteVisibility')->will($this->returnValue($visibilityResult));
     $this->urlPersist->expects($this->exactly($expectedReplaceCount))->method('replace')->with([3 => 'rewrite']);
     $this->model->execute($this->observer);
 }
 /**
  * Generate product url rewrites
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 public function generate(Product $product)
 {
     if ($product->getVisibility() == Visibility::VISIBILITY_NOT_VISIBLE) {
         return [];
     }
     $this->product = $product;
     $storeId = $this->product->getStoreId();
     $productCategories = $product->getCategoryCollection()->addAttributeToSelect('url_key')->addAttributeToSelect('url_path');
     $urls = $this->isGlobalScope($storeId) ? $this->generateForGlobalScope($productCategories) : $this->generateForSpecificStoreView($storeId, $productCategories);
     $this->product = null;
     return $urls;
 }
Example #15
0
 /**
  * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product
  * @param array $modelData
  * @param bool $isUnlimited
  * @return \Magento\Downloadable\Model\Link|\PHPUnit_Framework_MockObject_MockObject
  */
 private function createLinkkModel($product, array $modelData, $isUnlimited)
 {
     $link = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Link')->disableOriginalConstructor()->setMethods(['setData', 'setLinkType', 'setProductId', 'setStoreId', 'setWebsiteId', 'setProductWebsiteIds', 'setPrice', 'setNumberOfDownloads', 'setSampleUrl', 'setSampleType', 'setLinkFile', 'setSampleFile', 'save', 'getIsUnlimited'])->getMock();
     $link->expects($this->once())->method('setData')->with($modelData)->will($this->returnSelf());
     $link->expects($this->once())->method('setLinkType')->with($modelData['type'])->will($this->returnSelf());
     $link->expects($this->once())->method('setProductId')->with($product->getId())->will($this->returnSelf());
     $link->expects($this->once())->method('setStoreId')->with($product->getStoreId())->will($this->returnSelf());
     $link->expects($this->once())->method('setWebsiteId')->with($product->getStore()->getWebsiteId())->will($this->returnSelf());
     $link->expects($this->once())->method('setPrice')->with(0);
     $link->expects($this->any())->method('setNumberOfDownloads')->with(0);
     $link->expects($this->once())->method('getIsUnlimited')->will($this->returnValue($isUnlimited));
     return $link;
 }
Example #16
0
 /**
  * Delete product data
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
  * @return $this
  */
 public function deleteProductData($product, $attribute)
 {
     $where = ['entity_id = ?' => (int) $product->getId(), 'attribute_id = ?' => (int) $attribute->getId()];
     $connection = $this->getConnection();
     if (!$attribute->isScopeGlobal()) {
         $storeId = $product->getStoreId();
         if ($storeId) {
             $where['website_id IN(?)'] = [0, $this->_storeManager->getStore($storeId)->getWebsiteId()];
         }
     }
     $connection->delete($this->getMainTable(), $where);
     return $this;
 }
Example #17
0
 /**
  * Minimal price for "regular" user
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param null|\Magento\Store\Model\Store $store Store view
  * @param bool $inclTax
  * @return null|float
  */
 public function getCatalogPrice(\Magento\Catalog\Model\Product $product, $store = null, $inclTax = false)
 {
     if ($store instanceof \Magento\Store\Model\Store) {
         $oldStore = $this->storeManager->getStore();
         $this->storeManager->setCurrentStore($store);
     }
     $this->coreRegistry->unregister('rule_data');
     $this->coreRegistry->register('rule_data', new \Magento\Framework\Object(array('store_id' => $product->getStoreId(), 'website_id' => $product->getWebsiteId(), 'customer_group_id' => $product->getCustomerGroupId())));
     $minPrice = $product->getPriceModel()->getTotalPrices($product, 'min', $inclTax);
     if ($store instanceof \Magento\Store\Model\Store) {
         $this->storeManager->setCurrentStore($oldStore);
     }
     return $minPrice;
 }
Example #18
0
 /**
  * Loads the values from a product model
  *
  * @param \Magento\Catalog\Model\Product $productModel
  * @return void
  */
 protected function populateBuilderWithAttributes(\Magento\Catalog\Model\Product $productModel)
 {
     $attributes = array();
     foreach ($productModel->getAttributes() as $attribute) {
         $attrCode = $attribute->getAttributeCode();
         $value = $productModel->getDataUsingMethod($attrCode) ?: $productModel->getData($attrCode);
         if (null !== $value) {
             if ($attrCode != 'entity_id') {
                 $attributes[$attrCode] = $value;
             }
         }
     }
     $attributes[ProductDataObject::STORE_ID] = $productModel->getStoreId();
     $this->productBuilder->populateWithArray($attributes);
     return;
 }
Example #19
0
 /**
  * After Save Attribute manipulation
  *
  * @param \Magento\Catalog\Model\Product $object
  * @return $this
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getAttributeCode());
     /**
      * Orig value is only for existing objects
      */
     $oridData = $object->getOrigData();
     $origValueExist = $oridData && array_key_exists($this->getAttribute()->getAttributeCode(), $oridData);
     if ($object->getStoreId() != 0 || !$value || $origValueExist) {
         return $this;
     }
     if ($this->getAttribute()->getIsGlobal() == \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE) {
         $baseCurrency = $this->_config->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, 'default');
         $storeIds = $object->getStoreIds();
         if (is_array($storeIds)) {
             foreach ($storeIds as $storeId) {
                 $storeCurrency = $this->_storeManager->getStore($storeId)->getBaseCurrencyCode();
                 if ($storeCurrency == $baseCurrency) {
                     continue;
                 }
                 $rate = $this->_currencyFactory->create()->load($baseCurrency)->getRate($storeCurrency);
                 if (!$rate) {
                     $rate = 1;
                 }
                 $newValue = $value * $rate;
                 $object->addAttributeUpdate($this->getAttribute()->getAttributeCode(), $newValue, $storeId);
             }
         }
     }
     return $this;
 }
Example #20
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $targetCountry = $this->_config->getTargetCountry($product->getStoreId());
     $value = $this->_config->getCountryInfo($targetCountry, 'language', $product->getStoreId());
     return $this->_setAttribute($entry, 'content_language', self::ATTRIBUTE_TYPE_TEXT, $value);
 }
Example #21
0
 /**
  * Get downloadable product samples
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Downloadable\Model\Resource\Sample\Collection
  */
 public function getSamples($product)
 {
     if ($product->getDownloadableSamples() === null) {
         $sampleCollection = $this->_samplesFactory->create()->addProductToFilter($product->getId())->addTitleToResult($product->getStoreId());
         $this->extensionAttributesJoinProcessor->process($sampleCollection);
         $product->setDownloadableSamples($sampleCollection);
     }
     return $product->getDownloadableSamples();
 }
Example #22
0
 /**
  * After Save Attribute manipulation
  *
  * @param \Magento\Catalog\Model\Product $object
  * @return $this
  */
 public function afterSave($object)
 {
     $websiteId = $this->_storeManager->getStore($object->getStoreId())->getWebsiteId();
     $isGlobal = $this->getAttribute()->isScopeGlobal() || $websiteId == 0;
     $priceRows = $object->getData($this->getAttribute()->getName());
     if (empty($priceRows)) {
         if ($isGlobal) {
             $this->_getResource()->deletePriceData($object->getId());
         } else {
             $this->_getResource()->deletePriceData($object->getId(), $websiteId);
         }
         return $this;
     }
     $old = array();
     $new = array();
     // prepare original data for compare
     $origGroupPrices = $object->getOrigData($this->getAttribute()->getName());
     if (!is_array($origGroupPrices)) {
         $origGroupPrices = array();
     }
     foreach ($origGroupPrices as $data) {
         if ($data['website_id'] > 0 || $data['website_id'] == '0' && $isGlobal) {
             $key = join('-', array_merge(array($data['website_id'], $data['cust_group']), $this->_getAdditionalUniqueFields($data)));
             $old[$key] = $data;
         }
     }
     // prepare data for save
     foreach ($priceRows as $data) {
         $hasEmptyData = false;
         foreach ($this->_getAdditionalUniqueFields($data) as $field) {
             if (empty($field)) {
                 $hasEmptyData = true;
                 break;
             }
         }
         if ($hasEmptyData || !isset($data['cust_group']) || !empty($data['delete'])) {
             continue;
         }
         if ($this->getAttribute()->isScopeGlobal() && $data['website_id'] > 0) {
             continue;
         }
         if (!$isGlobal && (int) $data['website_id'] == 0) {
             continue;
         }
         $key = join('-', array_merge(array($data['website_id'], $data['cust_group']), $this->_getAdditionalUniqueFields($data)));
         $useForAllGroups = $data['cust_group'] == CustomerGroupServiceInterface::CUST_GROUP_ALL;
         $customerGroupId = !$useForAllGroups ? $data['cust_group'] : 0;
         $new[$key] = array_merge(array('website_id' => $data['website_id'], 'all_groups' => $useForAllGroups ? 1 : 0, 'customer_group_id' => $customerGroupId, 'value' => $data['price']), $this->_getAdditionalUniqueFields($data));
     }
     $delete = array_diff_key($old, $new);
     $insert = array_diff_key($new, $old);
     $update = array_intersect_key($new, $old);
     $isChanged = false;
     $productId = $object->getId();
     if (!empty($delete)) {
         foreach ($delete as $data) {
             $this->_getResource()->deletePriceData($productId, null, $data['price_id']);
             $isChanged = true;
         }
     }
     if (!empty($insert)) {
         foreach ($insert as $data) {
             $price = new \Magento\Framework\Object($data);
             $price->setEntityId($productId);
             $this->_getResource()->savePriceData($price);
             $isChanged = true;
         }
     }
     if (!empty($update)) {
         foreach ($update as $k => $v) {
             if ($old[$k]['price'] != $v['value']) {
                 $price = new \Magento\Framework\Object(array('value_id' => $old[$k]['price_id'], 'value' => $v['value']));
                 $this->_getResource()->savePriceData($price);
                 $isChanged = true;
             }
         }
     }
     if ($isChanged) {
         $valueChangedKey = $this->getAttribute()->getName() . '_changed';
         $object->setData($valueChangedKey, 1);
     }
     return $this;
 }
Example #23
0
 /**
  * Retrieve Store Id
  *
  * @return int
  */
 public function getStoreId()
 {
     return (int) $this->_product->getStoreId();
 }
 public function testGetResourceCollection()
 {
     $collection = $this->_model->getResourceCollection();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', $collection);
     $this->assertEquals($this->_model->getStoreId(), $collection->getStoreId());
 }
Example #25
0
 /**
  * @param ComponentInterface $model
  * @param array $data
  * @param Product $product
  * @return void
  */
 protected function setDataToModel(ComponentInterface $model, array $data, Product $product)
 {
     $model->setData($data)->setLinkType($data['type'])->setProductId($product->getData($this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()))->setStoreId($product->getStoreId())->setWebsiteId($product->getStore()->getWebsiteId())->setProductWebsiteIds($product->getWebsiteIds());
     if (null === $model->getPrice()) {
         $model->setPrice(0);
     }
     if ($model->getIsUnlimited()) {
         $model->setNumberOfDownloads(0);
     }
 }
Example #26
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;
 }
Example #27
0
 /**
  * Get Product Option Collection
  *
  * @param Product $product
  * @return \Magento\Catalog\Model\ResourceModel\Product\Option\Collection
  */
 public function getProductOptionCollection(Product $product)
 {
     $collection = clone $this->getCollection();
     $collection->addFieldToFilter('product_id', $product->getId())->addTitleToResult($product->getStoreId())->addPriceToResult($product->getStoreId())->setOrder('sort_order', 'asc')->setOrder('title', 'asc');
     if ($this->getAddRequiredFilter()) {
         $collection->addRequiredFilter($this->getAddRequiredFilterValue());
     }
     $collection->addValuesToResult($product->getStoreId());
     return $collection;
 }
Example #28
0
 /**
  * Calculate price using catalog price rule of product
  *
  * @param Product $product
  * @param float $price
  * @return float|null
  */
 public function calcProductPriceRule(Product $product, $price)
 {
     $priceRules = null;
     $productId = $product->getId();
     $storeId = $product->getStoreId();
     $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
     if ($product->hasCustomerGroupId()) {
         $customerGroupId = $product->getCustomerGroupId();
     } else {
         $customerGroupId = $this->_customerSession->getCustomerGroupId();
     }
     $dateTs = $this->_localeDate->scopeTimeStamp($storeId);
     $cacheKey = date('Y-m-d', $dateTs) . "|{$websiteId}|{$customerGroupId}|{$productId}|{$price}";
     if (!array_key_exists($cacheKey, self::$_priceRulesData)) {
         $rulesData = $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $productId);
         if ($rulesData) {
             foreach ($rulesData as $ruleData) {
                 if ($product->getParentId()) {
                     if (!empty($ruleData['sub_simple_action'])) {
                         $priceRules = $this->_catalogRuleData->calcPriceRule($ruleData['sub_simple_action'], $ruleData['sub_discount_amount'], $priceRules ? $priceRules : $price);
                     } else {
                         $priceRules = $priceRules ? $priceRules : $price;
                     }
                     if ($ruleData['action_stop']) {
                         break;
                     }
                 } else {
                     $priceRules = $this->_catalogRuleData->calcPriceRule($ruleData['action_operator'], $ruleData['action_amount'], $priceRules ? $priceRules : $price);
                     if ($ruleData['action_stop']) {
                         break;
                     }
                 }
             }
             return self::$_priceRulesData[$cacheKey] = $priceRules;
         } else {
             self::$_priceRulesData[$cacheKey] = null;
         }
     } else {
         return self::$_priceRulesData[$cacheKey];
     }
     return null;
 }
Example #29
0
 /**
  * Custom setter for 'price' attribute
  *
  * @param Entry $entry
  * @param Product $product
  * @param mixed $value Fload price value
  * @param string $name Google Content attribute name
  * @return Entry
  */
 protected function _setAttributePrice($entry, $product, $value, $name = 'price')
 {
     $store = $this->_storeManager->getStore($product->getStoreId());
     $price = $store->convertPrice($value);
     return $this->_setAttribute($entry, $name, self::ATTRIBUTE_TYPE_FLOAT, sprintf('%.2f', $store->roundPrice($price)), $store->getDefaultCurrencyCode());
 }
Example #30
0
 /**
  * @param ComponentInterface $model
  * @param array $data
  * @param Product $product
  * @return void
  */
 protected function setDataToModel(ComponentInterface $model, array $data, Product $product)
 {
     $model->setData($data)->setSampleType($data['type'])->setProductId($product->getId())->setStoreId($product->getStoreId());
 }