本文整理汇总了PHP中Magento\Catalog\Model\Product::lockAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::lockAttribute方法的具体用法?PHP Product::lockAttribute怎么用?PHP Product::lockAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::lockAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* Initialize product before saving
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function initialize(\Magento\Catalog\Model\Product $product)
{
$productData = $this->request->getPost('product');
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);
}
foreach (['category_ids', 'website_ids'] as $field) {
if (!isset($productData[$field])) {
$productData[$field] = [];
}
}
$wasLockedMedia = false;
if ($product->isLockedAttribute('media')) {
$product->unlockAttribute('media');
$wasLockedMedia = true;
}
$product->addData($productData);
if ($wasLockedMedia) {
$product->lockAttribute('media');
}
if ($this->storeManager->hasSingleStore()) {
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
}
/**
* Check "Use Default Value" checkboxes values
*/
$useDefaults = $this->request->getPost('use_default');
if ($useDefaults) {
foreach ($useDefaults as $attributeCode) {
$product->setData($attributeCode, false);
}
}
$links = $this->request->getPost('links');
$links = is_array($links) ? $links : [];
$linkTypes = ['related', 'upsell', 'crosssell'];
foreach ($linkTypes as $type) {
if (isset($links[$type])) {
$links[$type] = $this->jsHelper->decodeGridSerializedInput($links[$type]);
}
}
$product = $this->productLinks->initializeLinks($product, $links);
/**
* Initialize product options
*/
if (isset($productData['options']) && !$product->getOptionsReadonly()) {
// mark custom options that should to fall back to default value
$options = $this->mergeProductOptions($productData['options'], $this->request->getPost('options_use_default'));
$product->setProductOptions($options);
}
$product->setCanSaveCustomOptions((bool) $this->request->getPost('affect_product_custom_options') && !$product->getOptionsReadonly());
return $product;
}
示例2: initialize
/**
* Initialize product before saving
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
*/
public function initialize(\Magento\Catalog\Model\Product $product)
{
$productData = $this->request->getPost('product');
if ($productData) {
$stockData = isset($productData['stock_data']) ? $productData['stock_data'] : array();
$productData['stock_data'] = $this->stockFilter->filter($stockData);
}
foreach (array('category_ids', 'website_ids') as $field) {
if (!isset($productData[$field])) {
$productData[$field] = array();
}
}
$wasLockedMedia = false;
if ($product->isLockedAttribute('media')) {
$product->unlockAttribute('media');
$wasLockedMedia = true;
}
$product->addData($productData);
if ($wasLockedMedia) {
$product->lockAttribute('media');
}
if ($this->storeManager->hasSingleStore()) {
$product->setWebsiteIds(array($this->storeManager->getStore(true)->getWebsite()->getId()));
}
/**
* Create Permanent Redirect for old URL key
*/
if ($product->getId() && isset($productData['url_key_create_redirect'])) {
$product->setData('save_rewrites_history', (bool) $productData['url_key_create_redirect']);
}
/**
* Check "Use Default Value" checkboxes values
*/
$useDefaults = $this->request->getPost('use_default');
if ($useDefaults) {
foreach ($useDefaults as $attributeCode) {
$product->setData($attributeCode, false);
}
}
$links = $this->request->getPost('links');
$links = is_array($links) ? $links : array();
$linkTypes = array('related', 'upsell', 'crosssell');
foreach ($linkTypes as $type) {
if (isset($links[$type])) {
$links[$type] = $this->jsHelper->decodeGridSerializedInput($links[$type]);
}
}
$product = $this->productLinks->initializeLinks($product, $links);
/**
* Initialize product options
*/
if (isset($productData['options']) && !$product->getOptionsReadonly()) {
$product->setProductOptions($productData['options']);
}
$product->setCanSaveCustomOptions((bool) $this->request->getPost('affect_product_custom_options') && !$product->getOptionsReadonly());
return $product;
}
示例3: testGetCategoryIds
public function testGetCategoryIds()
{
$this->model->lockAttribute('category_ids');
$this->assertEquals([], $this->model->getCategoryIds());
}
示例4: 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;
}
示例5: initialize
/**
* Initialize product before saving
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function initialize(\Magento\Catalog\Model\Product $product)
{
$productData = $this->request->getPost('product');
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);
}
foreach (['category_ids', 'website_ids'] as $field) {
if (!isset($productData[$field])) {
$productData[$field] = [];
}
}
$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->dateFilter;
}
}
}
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $productData);
$productData = $inputFilter->getUnescaped();
$product->addData($productData);
if ($wasLockedMedia) {
$product->lockAttribute('media');
}
if ($this->storeManager->hasSingleStore()) {
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
}
/**
* Check "Use Default Value" checkboxes values
*/
$useDefaults = $this->request->getPost('use_default');
if ($useDefaults) {
foreach ($useDefaults as $attributeCode) {
$product->setData($attributeCode, false);
}
}
$links = $this->request->getPost('links');
$links = is_array($links) ? $links : [];
$linkTypes = ['related', 'upsell', 'crosssell'];
foreach ($linkTypes as $type) {
if (isset($links[$type])) {
$links[$type] = $this->jsHelper->decodeGridSerializedInput($links[$type]);
}
}
$product = $this->productLinks->initializeLinks($product, $links);
$productLinks = $product->getProductLinks();
$linkTypes = ['related' => $product->getRelatedReadonly(), 'upsell' => $product->getUpsellReadonly(), 'crosssell' => $product->getCrosssellReadonly()];
foreach ($linkTypes as $linkType => $readonly) {
if (isset($links[$linkType]) && !$readonly) {
foreach ($links[$linkType] as $linkId => $linkData) {
$linkProduct = $this->productRepository->getById($linkId);
$link = $this->productLinkFactory->create();
$link->setSku($product->getSku())->setLinkedProductSku($linkProduct->getSku())->setLinkType($linkType)->setPosition(isset($linkData['position']) ? (int) $linkData['position'] : 0);
$productLinks[] = $link;
}
}
}
$product->setProductLinks($productLinks);
/**
* Initialize product options
*/
if (isset($productData['options']) && !$product->getOptionsReadonly()) {
// mark custom options that should to fall back to default value
$options = $this->mergeProductOptions($productData['options'], $this->request->getPost('options_use_default'));
$customOptions = [];
foreach ($options as $customOptionData) {
if (!(bool) $customOptionData['is_delete']) {
$customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
$customOption->setProductSku($product->getSku());
$customOption->setOptionId(null);
$customOptions[] = $customOption;
}
}
$product->setOptions($customOptions);
}
$product->setCanSaveCustomOptions((bool) $this->request->getPost('affect_product_custom_options') && !$product->getOptionsReadonly());
return $product;
}
示例6: lockAttribute
/**
* {@inheritdoc}
*/
public function lockAttribute($attributeCode)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'lockAttribute');
if (!$pluginInfo) {
return parent::lockAttribute($attributeCode);
} else {
return $this->___callPlugins('lockAttribute', func_get_args(), $pluginInfo);
}
}