Creation of product Variants in Ax 2012
Public void prodVariants(RefRecId _oldrecid, RefRecId _newRecid)
{
select ProductDimensionGroup from ecoResProductDimensionGroupProductloc
where ecoResProductDimensionGroupProductloc.Product == _oldrecid
join ecoResProductDimensionGroup
where ecoResProductDimensionGroup.RecId==ecoResProductDimensionGroupProductloc.ProductDimensionGroup;
if (ecoResProductDimensionGroup.Name=="Config")
{
while select productMasterConfiguration
where productMasterConfiguration.ConfigProductMaster== _oldrecid
{
productMasterConfigurationVariants = this.copyProdDimensionConfig(_newRecid , productMasterConfiguration);
ecoResConfiguration = EcoResConfiguration::find(productMasterConfigurationVariants.Configuration);
conVariants = EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,ecoResSize.Name,
ecoResColor.Name);
this.addVariantsToReleasedProduct(_newRecid,conVariants);
}
}
if (ecoResProductDimensionGroup.Name=="Size")
{
while select ecoResProductMasterSize
where ecoResProductMasterSize.SizeProductMaster == _oldrecid
{
ecoResProductMasterSizeVariants = this.copyProdDimensionsSIze(_newRecid , ecoResProductMasterSize);
ecoResSize = EcoResSize::find(ecoResProductMasterSizeVariants.Size);
conVariants = EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,ecoResSize.Name,
ecoResColor.Name);
this.addVariantsToReleasedProduct(_newRecid,conVariants);
}
}
if (ecoResProductDimensionGroup.Name=="color")
{
while select ecoResProductMastercolor
where ecoResProductMastercolor.ColorProductMaster == _oldrecid
{
ecoResProductMastercolorVariants = this.copyProdDimensionColur(_newRecid ,ecoResProductMastercolor);
ecoResColor = EcoResColor::find(ecoResProductMastercolorVariants.Color);
conVariants = EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,ecoResSize.Name,
ecoResColor.Name);
this.addVariantsToReleasedProduct(_newRecid,conVariants);
}
}
if (ecoResProductDimensionGroup.Name=="Style")
{
while select ecoResProductMasterStyle
where ecoResProductMasterStyle.StyleProductMaster == _oldrecid
{
ecoResProductMasterStyleVariants = this.copyProdDimensionsStyle(_newRecid ,ecoResProductMasterStyle);
ecoResStyle = EcoResStyle::find(ecoResProductMasterStyleVariants.Style);
conVariants = EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,ecoResSize.Name,
ecoResColor.Name,ecoResStyle.Name);
this.addVariantsToReleasedProduct(_newRecid,conVariants);
}
}
if (ecoResProductDimensionGroup.Name=="SizeCol")
{
while select ecoResProductMasterSize
where ecoResProductMasterSize.SizeProductMaster == _oldrecid
join ecoResProductMastercolor
where ecoResProductMastercolor.ColorProductMaster==ecoResProductMasterSize.SizeProductMaster
{
ecoResProductMasterSizeVariants = this.copyProdDimensionsSIze(_newRecid , ecoResProductMasterSize);
ecoResSize = EcoResSize::find(ecoResProductMasterSizeVariants.Size);
ecoResProductMastercolorVariants = this.copyProdDimensionColur(_newRecid ,ecoResProductMastercolor);
ecoResColor = EcoResColor::find(ecoResProductMastercolorVariants.Color);
conVariants = EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,ecoResSize.Name,
ecoResColor.Name,ecoResStyle.Name);
this.addVariantsToReleasedProduct(_newRecid,conVariants);
}
}
if (ecoResProductDimensionGroup.Name=="ColorStyle")
{
while select ecoResProductMastercolor
where ecoResProductMastercolor.ColorProductMaster == _oldrecid
join ecoResProductMasterStyle
where ecoResProductMasterStyle.StyleProductMaster ==ecoResProductMastercolor.ColorProductMaster
{
ecoResProductMastercolorVariants = this.copyProdDimensionColur(_newRecid ,ecoResProductMastercolor);
ecoResColor = EcoResColor::find(ecoResProductMastercolorVariants.Color);
ecoResProductMasterStyleVariants = this.copyProdDimensionsStyle(_newRecid ,ecoResProductMasterStyle);
ecoResStyle = EcoResStyle::find(ecoResProductMasterStyleVariants.Style);
conVariants = EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,ecoResSize.Name,
ecoResColor.Name,ecoResStyle.Name);
this.addVariantsToReleasedProduct(_newRecid,conVariants);
}
}
}
private void addVariantsToReleasedProduct(RefRecId _productMasterRecId,
container _con)
{
EcoResProductReleaseManagerBase releaseManager;
Name configId;
// i=1;
if (_productMasterRecId)
{
ecoResDistinctProductVariant = EcoResProductVariantManager::findDistinctProductVariant(_productMasterRecId,_con);
if (!ecoresdistinctproductvariant)
{
ecoresproductvariantmanager::createproductvariant(_productMasterRecId,
ecoresproduct::find(_productMasterRecId).searchname + ecoresconfiguration.name,
_con);
//info("product variants created");
//con = _con;
//while (i<=conLen(con))
//{
//configId = conPeek(con,i);
}
while select ecoResDistinctProductVariant
where ecoResDistinctProductVariant.ProductMaster == _productMasterRecId //&&
//ecoResDistinctProductVariant.DisplayProductNumber == EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(ecoResProductMaster.productNumber(),
{ //EcoResProductVariantDimValue::getDimensionValuesContainer(configId));
if (ecoResDistinctProductVariant && !ecoResDistinctProductVariant.isReleased())
{
releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);
releaseManager.release();
}
// i++;
}
//info('Product variants released');
}
}