本文整理匯總了PHP中Magento\CatalogImportExport\Model\Import\Product::getBehavior方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::getBehavior方法的具體用法?PHP Product::getBehavior怎麽用?PHP Product::getBehavior使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\CatalogImportExport\Model\Import\Product
的用法示例。
在下文中一共展示了Product::getBehavior方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isAttributeValid
/**
* @param string $attrCode
* @param array $attrParams
* @param array $rowData
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function isAttributeValid($attrCode, array $attrParams, array $rowData)
{
$this->_rowData = $rowData;
if (!empty($attrParams['apply_to']) && !in_array($rowData['product_type'], $attrParams['apply_to'])) {
return true;
}
if ($attrCode == Product::COL_SKU || $attrParams['is_required'] && ($this->context->getBehavior() == \Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE || $this->context->getBehavior() == \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND && !isset($this->context->getOldSku()[$rowData[$attrCode]]))) {
if (!isset($rowData[$attrCode]) || !strlen(trim($rowData[$attrCode]))) {
$valid = false;
$this->_addMessages([sprintf($this->context->retrieveMessageTemplate(RowValidatorInterface::ERROR_VALUE_IS_REQUIRED), $attrCode)]);
return $valid;
}
}
if (!strlen(trim($rowData[$attrCode]))) {
return true;
}
switch ($attrParams['type']) {
case 'varchar':
case 'text':
$valid = $this->textValidation($attrCode, $attrParams['type']);
break;
case 'decimal':
case 'int':
$valid = $this->numericValidation($attrCode, $attrParams['type']);
break;
case 'select':
case 'boolean':
case 'multiselect':
$values = explode(Product::PSEUDO_MULTI_LINE_SEPARATOR, $rowData[$attrCode]);
$valid = true;
foreach ($values as $value) {
$valid = $valid || isset($attrParams['options'][strtolower($value)]);
}
if (!$valid) {
$this->_addMessages([sprintf($this->context->retrieveMessageTemplate(RowValidatorInterface::ERROR_INVALID_ATTRIBUTE_OPTION), $attrCode)]);
}
break;
case 'datetime':
$val = trim($rowData[$attrCode]);
$valid = strtotime($val) !== false;
if (!$valid) {
$this->_addMessages([RowValidatorInterface::ERROR_INVALID_ATTRIBUTE_TYPE]);
}
break;
default:
$valid = true;
break;
}
if ($valid && !empty($attrParams['is_unique'])) {
if (isset($this->_uniqueAttributes[$attrCode][$rowData[$attrCode]]) && $this->_uniqueAttributes[$attrCode][$rowData[$attrCode]] != $rowData[Product::COL_SKU]) {
$this->_addMessages([RowValidatorInterface::ERROR_DUPLICATE_UNIQUE_ATTRIBUTE]);
return false;
}
$this->_uniqueAttributes[$attrCode][$rowData[$attrCode]] = $rowData[Product::COL_SKU];
}
return (bool) $valid;
}
示例2: isRequiredAttributeValid
/**
* @param string $attrCode
* @param array $attributeParams
* @param array $rowData
* @return bool
*/
public function isRequiredAttributeValid($attrCode, array $attributeParams, array $rowData)
{
$doCheck = false;
if ($attrCode == Product::COL_SKU) {
$doCheck = true;
} elseif ($attributeParams['is_required'] && $this->getRowScope($rowData) == Product::SCOPE_DEFAULT && $this->context->getBehavior() != \Magento\ImportExport\Model\Import::BEHAVIOR_DELETE) {
$doCheck = true;
}
return $doCheck ? isset($rowData[$attrCode]) && strlen(trim($rowData[$attrCode])) : true;
}
示例3: afterImportData
/**
* @param ImportProduct $import
* @param bool $result
* @return bool
*/
public function afterImportData(ImportProduct $import, $result)
{
if ($import->getAffectedEntityIds()) {
foreach ($import->getAffectedEntityIds() as $productId) {
$product = $this->productRepository->getById($productId);
$productUrls = $this->productUrlRewriteGenerator->generate($product);
if ($productUrls) {
$this->urlPersist->replace($productUrls);
}
}
} elseif (ImportExport::BEHAVIOR_DELETE == $import->getBehavior()) {
$this->clearProductUrls($import);
}
return $result;
}