本文整理匯總了PHP中Magento\CatalogImportExport\Model\Import\Product::getOldSku方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::getOldSku方法的具體用法?PHP Product::getOldSku怎麽用?PHP Product::getOldSku使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\CatalogImportExport\Model\Import\Product
的用法示例。
在下文中一共展示了Product::getOldSku方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: clearProductUrls
/**
* @param ImportProduct $import
* @return void
*/
protected function clearProductUrls(ImportProduct $import)
{
$oldSku = $import->getOldSku();
while ($bunch = $import->getNextBunch()) {
$idToDelete = [];
foreach ($bunch as $rowNum => $rowData) {
if ($import->validateRow($rowData, $rowNum) && ImportProduct::SCOPE_DEFAULT == $import->getRowScope($rowData)) {
$idToDelete[] = $oldSku[$rowData[ImportProduct::COL_SKU]]['entity_id'];
}
}
foreach ($idToDelete as $productId) {
$this->urlPersist->deleteByData([UrlRewrite::ENTITY_ID => $productId, UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE]);
}
}
}