本文整理匯總了PHP中Magento\CatalogImportExport\Model\Import\Product::isAttributeValid方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::isAttributeValid方法的具體用法?PHP Product::isAttributeValid怎麽用?PHP Product::isAttributeValid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\CatalogImportExport\Model\Import\Product
的用法示例。
在下文中一共展示了Product::isAttributeValid方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isRowValid
/**
* Validate row attributes. Pass VALID row data ONLY as argument.
*
* @param array $rowData
* @param int $rowNum
* @param bool $isNewProduct Optional
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
{
$error = false;
$rowScope = $this->_entityModel->getRowScope($rowData);
if (\Magento\CatalogImportExport\Model\Import\Product::SCOPE_NULL != $rowScope) {
foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
// check value for non-empty in the case of required attribute?
if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
$error |= !$this->_entityModel->isAttributeValid($attrCode, $attrParams, $rowData, $rowNum);
} elseif ($this->_isAttributeRequiredCheckNeeded($attrCode) && $attrParams['is_required']) {
// For the default scope - if this is a new product or
// for an old product, if the imported doc has the column present for the attrCode
if (\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT == $rowScope && ($isNewProduct || array_key_exists($attrCode, $rowData))) {
$this->_entityModel->addRowError(\Magento\CatalogImportExport\Model\Import\Product::ERROR_VALUE_IS_REQUIRED, $rowNum, $attrCode);
$error = true;
}
}
}
}
$error |= !$this->_isParticularAttributesValid($rowData, $rowNum);
return !$error;
}
示例2: testValidateDefaultScopeNotValidAttributesResetSku
public function testValidateDefaultScopeNotValidAttributesResetSku()
{
$sku = 'sku';
$rowNum = 0;
$attrCode = 'code';
$stringUtilsMock = $this->getMockBuilder('\\Magento\\Framework\\Stdlib\\StringUtils')->setMethods(null)->getMock();
$this->setPropertyValue($this->importProduct, 'string', $stringUtilsMock);
$scopeMock = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', ['getRowScope'], [], '', false);
$colStore = \Magento\CatalogImportExport\Model\Import\Product::COL_STORE;
$scopeRowData = [$sku => 'sku', $colStore => null];
$scopeResult = \Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT;
$scopeMock->expects($this->any())->method('getRowScope')->with($scopeRowData)->willReturn($scopeResult);
$oldSku = [$sku => ['type_id' => 'type_id_val']];
$this->setPropertyValue($this->importProduct, '_oldSku', $oldSku);
$expectedSku = false;
$newSku = ['attr_set_code' => 'new_attr_set_code', 'type_id' => 'new_type_id_val'];
$this->skuProcessor->expects($this->any())->method('getNewSku')->with($expectedSku)->willReturn($newSku);
$this->setPropertyValue($this->importProduct, 'skuProcessor', $this->skuProcessor);
$attrParams = ['type' => 'varchar'];
$attrRowData = ['code' => str_repeat('a', \Magento\CatalogImportExport\Model\Import\Product::DB_MAX_VARCHAR_LENGTH + 1)];
$this->validator->expects($this->once())->method('isAttributeValid')->willReturn(false);
$messages = ['validator message'];
$this->validator->expects($this->once())->method('getMessages')->willReturn($messages);
$result = $this->importProduct->isAttributeValid($attrCode, $attrParams, $attrRowData, $rowNum);
$this->assertFalse($result);
}
示例3: testIsAttributeValidAssertAttrInvalid
/**
* @dataProvider isAttributeValidAssertAttrInvalidDataProvider
*/
public function testIsAttributeValidAssertAttrInvalid($attrParams, $rowData)
{
$attrCode = 'code';
$rowNum = 0;
$string = $this->getMockBuilder('\\Magento\\Framework\\Stdlib\\String')->setMethods(null)->getMock();
$this->setPropertyValue($this->importProduct, 'string', $string);
$result = $this->importProduct->isAttributeValid($attrCode, $attrParams, $rowData, $rowNum);
$this->assertFalse($result);
}