本文整理汇总了PHP中Magento\Catalog\Api\Data\ProductInterface::setStoreId方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::setStoreId方法的具体用法?PHP ProductInterface::setStoreId怎么用?PHP ProductInterface::setStoreId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Api\Data\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::setStoreId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateLink
/**
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param LinkInterface $link
* @param bool $isGlobalScopeContent
* @return mixed
* @throws InputException
* @throws NoSuchEntityException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function updateLink(\Magento\Catalog\Api\Data\ProductInterface $product, LinkInterface $link, $isGlobalScopeContent)
{
/** @var $existingLink \Magento\Downloadable\Model\Link */
$existingLink = $this->linkFactory->create()->load($link->getId());
if (!$existingLink->getId()) {
throw new NoSuchEntityException(__('There is no downloadable link with provided ID.'));
}
if ($existingLink->getProductId() != $product->getId()) {
throw new InputException(__('Provided downloadable link is not related to given product.'));
}
$validateLinkContent = $link->getLinkFileContent() === null ? false : true;
$validateSampleContent = $link->getSampleFileContent() === null ? false : true;
if (!$this->contentValidator->isValid($link, $validateLinkContent, $validateSampleContent)) {
throw new InputException(__('Provided link information is invalid.'));
}
if ($isGlobalScopeContent) {
$product->setStoreId(0);
}
$title = $link->getTitle();
if (empty($title)) {
if ($isGlobalScopeContent) {
throw new InputException(__('Link title cannot be empty.'));
}
}
if ($link->getLinkType() == 'file' && $link->getLinkFileContent() === null) {
$link->setLinkFile($existingLink->getLinkFile());
}
if ($link->getSampleType() == 'file' && $link->getSampleFileContent() === null) {
$link->setSampleFile($existingLink->getSampleFile());
}
$this->saveLink($product, $link, $isGlobalScopeContent);
return $existingLink->getId();
}
示例2: updateSample
/**
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param SampleInterface $sample
* @param bool $isGlobalScopeContent
* @return int
* @throws InputException
* @throws NoSuchEntityException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function updateSample(\Magento\Catalog\Api\Data\ProductInterface $product, SampleInterface $sample, $isGlobalScopeContent)
{
$sampleId = $sample->getId();
/** @var $existingSample \Magento\Downloadable\Model\Sample */
$existingSample = $this->sampleFactory->create()->load($sampleId);
if (!$existingSample->getId()) {
throw new NoSuchEntityException(__('There is no downloadable sample with provided ID.'));
}
if ($existingSample->getProductId() != $product->getId()) {
throw new InputException(__('Provided downloadable sample is not related to given product.'));
}
$validateFileContent = $sample->getSampleFileContent() === null ? false : true;
if (!$this->contentValidator->isValid($sample, $validateFileContent)) {
throw new InputException(__('Provided sample information is invalid.'));
}
if ($isGlobalScopeContent) {
$product->setStoreId(0);
}
$title = $sample->getTitle();
if (empty($title)) {
if ($isGlobalScopeContent) {
throw new InputException(__('Sample title cannot be empty.'));
}
// use title from GLOBAL scope
$existingSample->setTitle(null);
} else {
$existingSample->setTitle($sample->getTitle());
}
if ($sample->getSampleType() === 'file' && $sample->getSampleFileContent() === null) {
$sample->setSampleFile($existingSample->getSampleFile());
}
$this->saveSample($product, $sample, $isGlobalScopeContent);
return $existingSample->getId();
}