public function testGetStoreIds()
 {
     $expectedStoreIds = [1, 2, 3];
     $websiteIds = ['test'];
     $this->resource->expects($this->once())->method('getWebsiteIds')->will($this->returnValue($websiteIds));
     $this->website->expects($this->once())->method('getStoreIds')->will($this->returnValue($expectedStoreIds));
     $this->assertEquals($expectedStoreIds, $this->model->getStoreIds());
 }
 public function testGetStoreIds()
 {
     // set
     /** @var $model \Magento\Catalog\Model\Product */
     $model = $this->objectManager->create('Magento\\Catalog\\Model\\Product', ['data' => ['store_ids' => [1, 2]]]);
     $this->assertEquals([1, 2], $model->getStoreIds());
     // fixture
     $this->_model->setId($this->productRepository->get('simple')->getId());
     $this->assertEquals([1], $this->_model->getStoreIds());
 }
 public function testGetStoreIds()
 {
     // set
     /** @var $model \Magento\Catalog\Model\Product */
     $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product', ['data' => ['store_ids' => [1, 2]]]);
     $this->assertEquals([1, 2], $model->getStoreIds());
     // fixture
     $this->_model->setId(1);
     $this->assertEquals([1], $this->_model->getStoreIds());
 }
Example #4
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;
 }
 /**
  * Generate list of urls for global scope
  *
  * @param \Magento\Framework\Data\Collection $productCategories
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 protected function generateForGlobalScope($productCategories)
 {
     $urls = [];
     $productId = $this->product->getId();
     foreach ($this->product->getStoreIds() as $id) {
         if (!$this->isGlobalScope($id) && !$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore($id, $productId, Product::ENTITY)) {
             $urls = array_merge($urls, $this->generateForSpecificStoreView($id, $productCategories));
         }
     }
     return $urls;
 }
Example #6
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;
 }
 /**
  * {@inheritdoc}
  */
 public function getStoreIds()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getStoreIds');
     if (!$pluginInfo) {
         return parent::getStoreIds();
     } else {
         return $this->___callPlugins('getStoreIds', func_get_args(), $pluginInfo);
     }
 }