When you sync Template Items to BigCommerce, the Matrix Items in TemplateItem will be mapped to product variant in BC side. If you don’t want to use the default price mapping, and want to use the specified price in Matrix item attribute instead, the following customization project can help you.
public class BCTemplateItemProcessor_Extension : PXGraphExtension<BCTemplateItemProcessor>
{
//The code is active only if BigCommerce connector feature is enabled.
public static bool IsActive() => CommerceFeaturesHelper.BigCommerceConnector;
//Specify the attribut ID to get the price.
protected const string AttributeId = "RTLWEBPRC";
#region Event Handlers
public delegate void MapBucketExportDelegate(BCProductWithVariantEntityBucket bucket, IMappedEntity existing);
PXOverride]
public void MapBucketExport(BCProductWithVariantEntityBucket bucket, IMappedEntity existing, MapBucketExportDelegate baseMethod)
{
baseMethod(bucket, existing);
TemplateItems impl = bucket.Product?.Local;
//All attributes in Matrix item have been saved in AttributesValues.
if (impl != null && impl.Matrix?.Any() == true && impl.AttributesValues?.Any() == true)
{
//Find the attribute that you want to use, you can only use AttributeID here, AttributeDescription doesn't work here.
var priceAttributes = impl.AttributesValues.Where(a => string.Equals(a.AttributeID.Value, AttributeId, StringComparison.OrdinalIgnoreCase));
impl.Matrix.ForEach(x => {
//Loop all matrix items, find the associated attribute with NoteID
var matchedPriceAttribute = priceAttributes.FirstOrDefault(p => p.NoteID.Value == x.Id);
if (matchedPriceAttribute != null && !string.IsNullOrEmpty(matchedPriceAttribute.Value?.Value))
{
if (Decimal.TryParse(matchedPriceAttribute.Value?.Value, out var result))
{
x.DefaultPrice = result.ValueField();
}
}
//This is the list that you can change the mapping value in this customization:
//Example: x.DefaultPrice = 10, the price in variant will be assigned to 10.
//price : DefaultPrice
//retail_price : MSRP
//weight : BaseItemWeight
});
}
}
#endregion
}
Note: you cannot use the entity mapping to change the mapping for product variant level in current version.