Friday 14 December 2018

Update Variant Sizes based on Configuration

Recently in a project, there was a scenario where the sizes had an incorrect display order imported when the configuration was imported. On the size groups, the data seemed correct. To tackle that, the following job was created. It looks at the correct display order from the configuration and populates it to the variant configuration.

static void UpdateProductSizeDisplayOrder(Args _args)
{
    InventTable inventTable;
    EcoResProductMasterDimensionValue dimValue;
    EcoResProductMasterSize prodMasterSize;
    EcoResDistinctProduct disProduct;
    RetailSizeGroupTrans retailSizeGroupTrans;
    CommaIo file;
    int iCount=0;

    ;
    file = new CommaIo(@"\\XXX\ProdSizes_PROD_NEW"+".csv","W");

    file.write("ItemId","Size","sizeRecId","DisplayOrder","SizeGroup","CorrectDisplayOrder","ChangeMade");
    while select inventTable // where inventTable.ItemId == 'B4E2200'
    {
        while select forupdate prodMasterSize where prodMasterSize.SizeProductMaster == inventTable.Product
        {
            select retailSizeGroupTrans where retailSizeGroupTrans.size == EcoResSize::find(prodMasterSize.Size).Name
            && retailSizeGroupTrans.sizeGroup == EcoResProductMaster::find(prodMasterSize.SizeProductMaster).RetailSizeGroupId;



            if(prodMasterSize.RetailDisplayOrder != retailSizeGroupTrans.DisplayOrder)
            {
                file.write(
                            inventTable.ItemId,
                            EcoResSize::find(prodMasterSize.Size).Name,
                            prodMasterSize.RecId,
                            prodMasterSize.RetailDisplayOrder,
                            EcoResProductMaster::find(prodMasterSize.SizeProductMaster).RetailSizeGroupId,
                            retailSizeGroupTrans.DisplayOrder,"YES"
                            );

                ttsBegin;
                prodMasterSize.RetailDisplayOrder = retailSizeGroupTrans.DisplayOrder;
                prodMasterSize.update();
                ttsCommit;

                iCount++;
            }
            else
            {
                file.write( inventTable.ItemId,
            EcoResSize::find(prodMasterSize.Size).Name,
            prodMasterSize.RecId,
            prodMasterSize.RetailDisplayOrder,
            EcoResProductMaster::find(prodMasterSize.SizeProductMaster).RetailSizeGroupId,
            retailSizeGroupTrans.DisplayOrder,"NO");
            }

        }
    }
        info("Finished");
}