Saturday 25 May 2013

Creating a product master with variants with X++

Hi all, recently I had to do something tricky with the data import/export framework and now I want to share it :-)

I had to create product masters but also add configurations to the product dimensions and later release this products with it new configurations so they could be used on the released company.

The data import/export framework have so far a entity to create product masters but it seems that there is not an implementation to release product versions with new configurations. So what I did is to add a method to the class DMFProductMasterEntityClass and 2 new fiels on the source CSV file with the Configuration Name and the Configuration Description. When properly setup, the new method would be executed on the copying from staging to target using these 2 new values on the CSV.

And below a example code to add the configurations to a product master and release the master product but also the configuration.

EcoResDistinctProductVariant ecoResDistinctProductVariant;
EcoResProductVariantDimensionValue EcoResProductVariantDimensionValue;
RefRecId ecoResDistinctProductVariantRecId;
EcoResProductReleaseManagerBase releaseManager;

c
ontainer productDimensions;
EcoResProductNumber EcoResProductNumber = "MyProductNumber";
EcoResProduct EcoResProduct = EcoResProduct::findByProductNumber(EcoResProductNumber);
;

EcoResProductMasterManager::addProductDimensionValue( ecoResProduct.RecId,
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(

fieldNum(InventDim, ConfigId)),
'Variation1',
'Variation Description',                         'Variation Description');

 

productDimensions = EcoResProductVariantDimValue::getDimensionValuesContainer(
"Variation1");

//Create Product search name
ecoResDistinctProductVariant.DisplayProductNumber = EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(
EcoResProductNumber,
productDimensions);

//Create Product variant with Product and dimensions provided
ecoResDistinctProductVariant = EcoResProductVariantManager::findDistinctProductVariant(EcoResProduct.RecId, productDimensions);
if (!ecoResDistinctProductVariant)
{
ecoResDistinctProductVariantRecId = EcoResProductVariantManager::createProductVariant(EcoResProduct.RecId,
ecoResDistinctProductVariant.DisplayProductNumber,
productDimensions);
}
else
{
ecoResDistinctProductVariantRecId = ecoResDistinctProductVariant.RecId;
}

//Find newly created Product Variant
ecoResDistinctProductVariant = ecoResDistinctProductVariant::find(ecoResDistinctProductVariantRecId);
//Now release the Product
if (!EcoResProduct.isReleased())
{
EcoResProductReleaseManagerBase::releaseProduct(EcoResProduct.RecId, CompanyInfo::findDataArea(
curext()).RecId);

info("Product released");

}

//Now release the Product Variant
if (ecoResDistinctProductVariant && !ecoResDistinctProductVariant.isReleased())
{
releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);
releaseManager.release();
info(
"Product variante released");
}

I have to say that the customer delivered a CSV file in which I had a record for each configuration but the rest of the fields where repeated like the product number, product search name, prices, ... and so on. Only was new the configuration name and the configuration description. But that was not a problem as for each record the data import/export framework would create or update (if already exists the product master) but also add the new configuration information for each product master. Only I had to modify the index of the DMFProductMasterEntity so I could load has staging data repeated product master numbers but with diferent configuration...

Ok that is for now...on the next days I have lot to do with the data import/export framework...maybe I can find something interesting to write...now I finish just on time to watch the great football match of the year here in Germany. The final of the Europa League between Dortmund and Bayer. Sadly the spanish teams were seriously beaten by the germans :-(

No comments:

Post a Comment