本文整理匯總了PHP中Pim\Bundle\CatalogBundle\Model\ProductInterface::isAttributeEditable方法的典型用法代碼示例。如果您正苦於以下問題:PHP ProductInterface::isAttributeEditable方法的具體用法?PHP ProductInterface::isAttributeEditable怎麽用?PHP ProductInterface::isAttributeEditable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Pim\Bundle\CatalogBundle\Model\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::isAttributeEditable方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: updateProduct
/**
* Set data from $actions to the given $product
*
* Actions should looks like that
*
* $actions =
* [
* [
* 'field' => 'group',
* 'value' => 'summer_clothes',
* 'options' => null
* ],
* [
* 'field' => 'category',
* 'value' => 'catalog_2013,catalog_2014',
* 'options' => null
* ],
* ]
*
* @param ProductInterface $product
* @param array $actions
*
* @throws \LogicException
*
* @return ProductInterface $product
*/
protected function updateProduct(ProductInterface $product, array $actions)
{
$modifiedAttributesNb = 0;
foreach ($actions as $action) {
$attribute = $this->attributeRepository->findOneBy(['code' => $action['field']]);
if (null === $attribute) {
throw new \LogicException(sprintf('Attribute with code %s does not exist'), $action['field']);
}
if ($product->isAttributeEditable($attribute)) {
$this->propertySetter->setData($product, $action['field'], $action['value'], $action['options']);
$modifiedAttributesNb++;
}
}
if (0 === $modifiedAttributesNb) {
$this->stepExecution->incrementSummaryInfo('skipped_products');
$this->stepExecution->addWarning($this->getName(), 'pim_enrich.mass_edit_action.edit-common-attributes.message.no_valid_attribute', [], $product);
return null;
}
return $product;
}