当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::getWebsiteIds方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product::getWebsiteIds方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getWebsiteIds方法的具体用法?PHP Product::getWebsiteIds怎么用?PHP Product::getWebsiteIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::getWebsiteIds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: copy

 /**
  * Create product duplicate
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function copy(\Magento\Catalog\Model\Product $product)
 {
     $product->getWebsiteIds();
     $product->getCategoryIds();
     $duplicate = $this->productFactory->create();
     $duplicate->setData($product->getData());
     $duplicate->setIsDuplicate(true);
     $duplicate->setOriginalId($product->getId());
     $duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
     $duplicate->setCreatedAt(null);
     $duplicate->setUpdatedAt(null);
     $duplicate->setId(null);
     $duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $this->copyConstructor->build($product, $duplicate);
     $isDuplicateSaved = false;
     do {
         $urlKey = $duplicate->getUrlKey();
         $urlKey = preg_match('/(.*)-(\\d+)$/', $urlKey, $matches) ? $matches[1] . '-' . ($matches[2] + 1) : $urlKey . '-1';
         $duplicate->setUrlKey($urlKey);
         try {
             $duplicate->save();
             $isDuplicateSaved = true;
         } catch (DuplicateEntryException $e) {
         }
     } while (!$isDuplicateSaved);
     $product->getOptionInstance()->duplicate($product->getId(), $duplicate->getId());
     $product->getResource()->duplicate($product->getId(), $duplicate->getId());
     return $duplicate;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:35,代码来源:Copier.php

示例2: copy

 /**
  * Create product duplicate
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function copy(\Magento\Catalog\Model\Product $product)
 {
     $product->getWebsiteIds();
     $product->getCategoryIds();
     /** @var \Magento\Catalog\Model\Product $duplicate */
     $duplicate = $this->productFactory->create();
     $duplicate->setData($product->getData());
     $duplicate->setOptions([]);
     $duplicate->setIsDuplicate(true);
     $duplicate->setOriginalId($product->getEntityId());
     $duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
     $duplicate->setCreatedAt(null);
     $duplicate->setUpdatedAt(null);
     $duplicate->setId(null);
     $duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $this->copyConstructor->build($product, $duplicate);
     $isDuplicateSaved = false;
     do {
         $urlKey = $duplicate->getUrlKey();
         $urlKey = preg_match('/(.*)-(\\d+)$/', $urlKey, $matches) ? $matches[1] . '-' . ($matches[2] + 1) : $urlKey . '-1';
         $duplicate->setUrlKey($urlKey);
         try {
             $duplicate->save();
             $isDuplicateSaved = true;
         } catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
         }
     } while (!$isDuplicateSaved);
     $this->getOptionRepository()->duplicate($product, $duplicate);
     $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
     $product->getResource()->duplicate($product->getData($metadata->getLinkField()), $duplicate->getData($metadata->getLinkField()));
     return $duplicate;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:38,代码来源:Copier.php

示例3: testGetWebsiteIds

 public function testGetWebsiteIds()
 {
     // set
     /** @var $model \Magento\Catalog\Model\Product */
     $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product', ['data' => ['website_ids' => [1, 2]]]);
     $this->assertEquals([1, 2], $model->getWebsiteIds());
     // fixture
     $this->_model->setId(1);
     $this->assertEquals([1], $this->_model->getWebsiteIds());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:ProductExternalTest.php

示例4: testGetWebsiteIds

 public function testGetWebsiteIds()
 {
     // set
     /** @var $model \Magento\Catalog\Model\Product */
     $model = $this->objectManager->create('Magento\\Catalog\\Model\\Product', ['data' => ['website_ids' => [1, 2]]]);
     $this->assertEquals([1, 2], $model->getWebsiteIds());
     // fixture
     $this->_model->setId($this->productRepository->get('simple')->getId());
     $this->assertEquals([1], $this->_model->getWebsiteIds());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:10,代码来源:ProductExternalTest.php

示例5: processCategoriesActions

 private function processCategoriesActions(\Magento\Catalog\Model\Product $product)
 {
     $productCategories = $product->getCategoryIds();
     $categoriesByWebsite = array(0 => $productCategories);
     foreach ($product->getWebsiteIds() as $websiteId) {
         $categoriesByWebsite[$websiteId] = $productCategories;
     }
     /** @var \Ess\M2ePro\Model\Listing\Auto\Actions\Mode\Category $autoActionsCategory */
     $autoActionsCategory = $this->modelFactory->getObject('Listing\\Auto\\Actions\\Mode\\Category');
     $autoActionsCategory->setProduct($product);
     foreach ($categoriesByWebsite as $websiteId => $categoryIds) {
         foreach ($categoryIds as $categoryId) {
             $autoActionsCategory->synchWithAddedCategoryId($categoryId, $websiteId);
         }
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:AddedProducts.php

示例6: copy

 /**
  * Create product duplicate
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function copy(\Magento\Catalog\Model\Product $product)
 {
     $product->getWebsiteIds();
     $product->getCategoryIds();
     $duplicate = $this->productFactory->create();
     $duplicate->setData($product->getData());
     $duplicate->setIsDuplicate(true);
     $duplicate->setOriginalId($product->getId());
     $duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
     $duplicate->setCreatedAt(null);
     $duplicate->setUpdatedAt(null);
     $duplicate->setId(null);
     $duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $this->copyConstructor->build($product, $duplicate);
     $duplicate->save();
     $product->getOptionInstance()->duplicate($product->getId(), $duplicate->getId());
     $product->getResource()->duplicate($product->getId(), $duplicate->getId());
     return $duplicate;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:25,代码来源:Copier.php

示例7: _printAssignedWebsites

 /**
  * @param \Magento\Catalog\Model\Product $product
  */
 protected function _printAssignedWebsites(\Magento\Catalog\Model\Product $product)
 {
     if (!$this->_printWebsites) {
         return;
     }
     $collection = $this->_websitesFactory->create();
     $collection->addIdFilter($product->getWebsiteIds());
     $websiteNames = array();
     /** @var \Magento\Store\Model\Website $website */
     foreach ($collection as $website) {
         $websiteNames[] = $website->getName();
     }
     echo 'Websites ';
     echo '[' . implode(',', $websiteNames) . ']';
     echo "\t";
 }
开发者ID:itmyprofession,项目名称:magento2-example-cataloglist,代码行数:19,代码来源:ListCatalogCommand.php

示例8: _saveWebsiteIds

 /**
  * Save product website relations
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 protected function _saveWebsiteIds($product)
 {
     $websiteIds = $product->getWebsiteIds();
     $oldWebsiteIds = [];
     $product->setIsChangedWebsites(false);
     $connection = $this->getConnection();
     $oldWebsiteIds = $this->getWebsiteIds($product);
     $insert = array_diff($websiteIds, $oldWebsiteIds);
     $delete = array_diff($oldWebsiteIds, $websiteIds);
     if (!empty($insert)) {
         $data = [];
         foreach ($insert as $websiteId) {
             $data[] = ['product_id' => (int) $product->getId(), 'website_id' => (int) $websiteId];
         }
         $connection->insertMultiple($this->getProductWebsiteTable(), $data);
     }
     if (!empty($delete)) {
         foreach ($delete as $websiteId) {
             $condition = ['product_id = ?' => (int) $product->getId(), 'website_id = ?' => (int) $websiteId];
             $connection->delete($this->getProductWebsiteTable(), $condition);
         }
     }
     if (!empty($insert) || !empty($delete)) {
         $product->setIsChangedWebsites(true);
     }
     return $this;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:33,代码来源:Product.php

示例9: testGetWebsiteIds

 public function testGetWebsiteIds()
 {
     $expected = ['test'];
     $this->resource->expects($this->once())->method('getWebsiteIds')->will($this->returnValue($expected));
     $this->assertEquals($expected, $this->model->getWebsiteIds());
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:6,代码来源:ProductTest.php

示例10: initializeFromData

 /**
  * Initialize product from data
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $productData
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function initializeFromData(\Magento\Catalog\Model\Product $product, array $productData)
 {
     unset($productData['custom_attributes']);
     unset($productData['extension_attributes']);
     if ($productData) {
         $stockData = isset($productData['stock_data']) ? $productData['stock_data'] : [];
         $productData['stock_data'] = $this->stockFilter->filter($stockData);
     }
     $productData = $this->normalize($productData);
     if (!empty($productData['is_downloadable'])) {
         $productData['product_has_weight'] = 0;
     }
     foreach (['category_ids', 'website_ids'] as $field) {
         if (!isset($productData[$field])) {
             $productData[$field] = [];
         }
     }
     foreach ($productData['website_ids'] as $websiteId => $checkboxValue) {
         if (!$checkboxValue) {
             unset($productData['website_ids'][$websiteId]);
         }
     }
     $wasLockedMedia = false;
     if ($product->isLockedAttribute('media')) {
         $product->unlockAttribute('media');
         $wasLockedMedia = true;
     }
     $dateFieldFilters = [];
     $attributes = $product->getAttributes();
     foreach ($attributes as $attrKey => $attribute) {
         if ($attribute->getBackend()->getType() == 'datetime') {
             if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
                 $dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
             }
         }
     }
     $inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $productData);
     $productData = $inputFilter->getUnescaped();
     if (isset($productData['options'])) {
         $productOptions = $productData['options'];
         unset($productData['options']);
     } else {
         $productOptions = [];
     }
     $product->addData($productData);
     if ($wasLockedMedia) {
         $product->lockAttribute('media');
     }
     if ($this->storeManager->hasSingleStore() && empty($product->getWebsiteIds())) {
         $product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
     }
     /**
      * Check "Use Default Value" checkboxes values
      */
     $useDefaults = (array) $this->request->getPost('use_default', []);
     foreach ($useDefaults as $attributeCode => $useDefaultState) {
         if ($useDefaultState) {
             $product->setData($attributeCode, null);
         }
     }
     $product = $this->setProductLinks($product);
     /**
      * Initialize product options
      */
     if ($productOptions && !$product->getOptionsReadonly()) {
         // mark custom options that should to fall back to default value
         $options = $this->mergeProductOptions($productOptions, $this->request->getPost('options_use_default'));
         $customOptions = [];
         foreach ($options as $customOptionData) {
             if (empty($customOptionData['is_delete'])) {
                 if (isset($customOptionData['values'])) {
                     $customOptionData['values'] = array_filter($customOptionData['values'], function ($valueData) {
                         return empty($valueData['is_delete']);
                     });
                 }
                 $customOption = $this->getCustomOptionFactory()->create(['data' => $customOptionData]);
                 $customOption->setProductSku($product->getSku());
                 $customOption->setOptionId(null);
                 $customOptions[] = $customOption;
             }
         }
         $product->setOptions($customOptions);
     }
     $product->setCanSaveCustomOptions(!empty($productData['affect_product_custom_options']) && !$product->getOptionsReadonly());
     return $product;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:96,代码来源:Helper.php

示例11: applyRule

 /**
  * @param Rule $rule
  * @param Product $product
  * @return $this
  * @throws \Exception
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function applyRule(Rule $rule, $product)
 {
     $ruleId = $rule->getId();
     $productEntityId = $product->getId();
     $websiteIds = array_intersect($product->getWebsiteIds(), $rule->getWebsiteIds());
     if (!$rule->validate($product)) {
         return $this;
     }
     $this->connection->delete($this->resource->getTableName('catalogrule_product'), [$this->connection->quoteInto('rule_id = ?', $ruleId), $this->connection->quoteInto('product_id = ?', $productEntityId)]);
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionAmount = $rule->getDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
     $subActionAmount = $rule->getSubDiscountAmount();
     $rows = [];
     try {
         foreach ($websiteIds as $websiteId) {
             foreach ($customerGroupIds as $customerGroupId) {
                 $rows[] = ['rule_id' => $ruleId, 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'customer_group_id' => $customerGroupId, 'product_id' => $productEntityId, 'action_operator' => $actionOperator, 'action_amount' => $actionAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder, 'sub_simple_action' => $subActionOperator, 'sub_discount_amount' => $subActionAmount];
                 if (count($rows) == $this->batchCount) {
                     $this->connection->insertMultiple($this->getTable('catalogrule_product'), $rows);
                     $rows = [];
                 }
             }
         }
         if (!empty($rows)) {
             $this->connection->insertMultiple($this->resource->getTableName('catalogrule_product'), $rows);
         }
     } catch (\Exception $e) {
         throw $e;
     }
     $this->applyAllRules($product);
     return $this;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:46,代码来源:IndexBuilder.php

示例12: assignProductToWebsites

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
 {
     if (!$this->storeManager->hasSingleStore()) {
         if ($this->storeManager->getStore()->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
             $websiteIds = array_keys($this->storeManager->getWebsites());
         } else {
             $websiteIds = [$this->storeManager->getStore()->getWebsiteId()];
         }
         $product->setWebsiteIds(array_unique(array_merge($product->getWebsiteIds(), $websiteIds)));
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:ProductRepository.php

示例13: _saveWebsiteIds

 /**
  * Save product website relations
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 protected function _saveWebsiteIds($product)
 {
     $websiteIds = $product->getWebsiteIds();
     $oldWebsiteIds = array();
     $product->setIsChangedWebsites(false);
     $adapter = $this->_getWriteAdapter();
     $oldWebsiteIds = $this->getWebsiteIds($product);
     $insert = array_diff($websiteIds, $oldWebsiteIds);
     $delete = array_diff($oldWebsiteIds, $websiteIds);
     if (!empty($insert)) {
         $data = array();
         foreach ($insert as $websiteId) {
             $data[] = array('product_id' => (int) $product->getId(), 'website_id' => (int) $websiteId);
         }
         $adapter->insertMultiple($this->_productWebsiteTable, $data);
     }
     if (!empty($delete)) {
         foreach ($delete as $websiteId) {
             $condition = array('product_id = ?' => (int) $product->getId(), 'website_id = ?' => (int) $websiteId);
             $adapter->delete($this->_productWebsiteTable, $condition);
         }
     }
     if (!empty($insert) || !empty($delete)) {
         $product->setIsChangedWebsites(true);
     }
     return $this;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:33,代码来源:Product.php

示例14: fillSimpleProductData

 /**
  * Fill simple product data during generation
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Catalog\Model\Product $parentProduct
  * @param array $postData
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @return void
  */
 protected function fillSimpleProductData(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $parentProduct, $postData)
 {
     $product->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID)->setTypeId($postData['weight'] ? ProductType::TYPE_SIMPLE : ProductType::TYPE_VIRTUAL)->setAttributeSetId($parentProduct->getNewVariationsAttributeSetId());
     foreach ($product->getTypeInstance()->getSetAttributes($product) as $attribute) {
         if ($attribute->getIsUnique() || $attribute->getAttributeCode() == 'url_key' || $attribute->getFrontend()->getInputType() == 'gallery' || $attribute->getFrontend()->getInputType() == 'media_image' || !$attribute->getIsVisible()) {
             continue;
         }
         $product->setData($attribute->getAttributeCode(), $parentProduct->getData($attribute->getAttributeCode()));
     }
     $keysFilter = ['item_id', 'product_id', 'stock_id', 'type_id', 'website_id'];
     $postData['stock_data'] = array_diff_key((array) $parentProduct->getStockData(), array_flip($keysFilter));
     if (!isset($postData['stock_data']['is_in_stock'])) {
         $stockStatus = $parentProduct->getQuantityAndStockStatus();
         $postData['stock_data']['is_in_stock'] = $stockStatus['is_in_stock'];
     }
     $postData = $this->processMediaGallery($product, $postData);
     $postData['status'] = isset($postData['status']) ? $postData['status'] : \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
     $product->addData($postData)->setWebsiteIds($parentProduct->getWebsiteIds())->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:30,代码来源:VariationHandler.php

示例15: getWebsiteIds

 /**
  * {@inheritdoc}
  */
 public function getWebsiteIds()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getWebsiteIds');
     if (!$pluginInfo) {
         return parent::getWebsiteIds();
     } else {
         return $this->___callPlugins('getWebsiteIds', func_get_args(), $pluginInfo);
     }
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:12,代码来源:Interceptor.php


注:本文中的Magento\Catalog\Model\Product::getWebsiteIds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。