本文整理汇总了PHP中Magento\Catalog\Model\Product::setStoreId方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::setStoreId方法的具体用法?PHP Product::setStoreId怎么用?PHP Product::setStoreId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::setStoreId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetStoreId
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());
}
示例2: prepareProducts
protected function prepareProducts()
{
$product = $this->product->loadByAttribute('sku', 'simple');
$product->load($product->getId());
$this->product = $product;
$this->product->setStoreId(0)->setData('test_attribute', 'test_attribute_value')->save();
$this->productSecond = clone $this->product;
$this->productSecond->setId(null)->setUrlKey('product-second')->save();
$this->productThird = clone $this->product;
$this->productThird->setId(null)->setUrlKey('product-third')->setData('test_attribute', 'NO_test_attribute_value')->save();
}
示例3: _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)
*/
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'] ? \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE : \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL)->setAttributeSetId($parentProduct->getNewVariationsAttributeSetId());
foreach ($product->getTypeInstance()->getEditableAttributes($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()));
}
$postData['stock_data'] = $parentProduct->getStockData();
$postData['stock_data']['manage_stock'] = $postData['quantity_and_stock_status']['qty'] === '' ? 0 : 1;
if (!isset($postData['stock_data']['is_in_stock'])) {
$stockStatus = $parentProduct->getQuantityAndStockStatus();
$postData['stock_data']['is_in_stock'] = $stockStatus['is_in_stock'];
}
$configDefaultValue = $this->stockConfiguration->getManageStock($product->getStoreId());
$postData['stock_data']['use_config_manage_stock'] = $postData['stock_data']['manage_stock'] == $configDefaultValue ? 1 : 0;
if (!empty($postData['image'])) {
$postData['small_image'] = $postData['thumbnail'] = $postData['image'];
$postData['media_gallery']['images'][] = ['position' => 1, 'file' => $postData['image'], 'disabled' => 0, 'label' => ''];
}
$product->addData($postData)->setWebsiteIds($parentProduct->getWebsiteIds())->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
}
示例4: setProduct
/**
* Setup product for quote item
*
* @param \Magento\Catalog\Model\Product $product
* @return $this
*/
public function setProduct($product)
{
if ($this->getQuote()) {
$product->setStoreId($this->getQuote()->getStoreId());
$product->setCustomerGroupId($this->getQuote()->getCustomerGroupId());
}
$this->setData('product', $product)->setProductId($product->getId())->setProductType($product->getTypeId())->setSku($this->getProduct()->getSku())->setName($product->getName())->setWeight($this->getProduct()->getWeight())->setTaxClassId($product->getTaxClassId())->setBaseCost($product->getCost());
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
$this->setIsQtyDecimal($stockItem->getIsQtyDecimal());
$this->_eventManager->dispatch('sales_quote_item_set_product', ['product' => $product, 'quote_item' => $this]);
return $this;
}
示例5: 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);
}
示例6: setStoreId
/**
* {@inheritdoc}
*/
public function setStoreId($storeId)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'setStoreId');
if (!$pluginInfo) {
return parent::setStoreId($storeId);
} else {
return $this->___callPlugins('setStoreId', func_get_args(), $pluginInfo);
}
}
示例7: setProduct
/**
* Setup product for quote item
*
* @param \Magento\Catalog\Model\Product $product
* @return $this
*/
public function setProduct($product)
{
if ($this->getQuote()) {
$product->setStoreId($this->getQuote()->getStoreId());
$product->setCustomerGroupId($this->getQuote()->getCustomerGroupId());
}
$this->setData('product', $product)->setProductId($product->getId())->setProductType($product->getTypeId())->setSku($this->getProduct()->getSku())->setName($product->getName())->setWeight($this->getProduct()->getWeight())->setTaxClassId($product->getTaxClassId())->setBaseCost($product->getCost());
/** @var \Magento\CatalogInventory\Service\V1\Data\StockItem $stockItemDo */
$stockItemDo = $this->stockItemService->getStockItem($product->getId());
if ($stockItemDo->getStockId()) {
$this->setIsQtyDecimal($stockItemDo->getIsQtyDecimal());
}
$this->_eventManager->dispatch('sales_quote_item_set_product', array('product' => $product, 'quote_item' => $this));
return $this;
}
示例8: setStoreToProduct
/**
* @param \Magento\Catalog\Model\Product $product
* @param array $rowData
* @return void
*/
protected function setStoreToProduct(\Magento\Catalog\Model\Product $product, array $rowData)
{
if (!empty($rowData[ImportProduct::COL_STORE]) && ($storeId = $this->import->getStoreIdByCode($rowData[ImportProduct::COL_STORE]))) {
$product->setStoreId($storeId);
} elseif (!$product->hasData(\Magento\Catalog\Model\Product::STORE_ID)) {
$product->setStoreId(Store::DEFAULT_STORE_ID);
}
}