简体   繁体   English

Dynamics CRM如何分辨C#捆绑包中的哪些产品

[英]Dynamics CRM How to tell which products are part of a bundle in C#

I have a program that bills a customer based on a custom entity. 我有一个基于自定义实体向客户收费的程序。 It is a subscription based process. 这是一个基于订阅的过程。 We enter an order, if that order has a product that has been defined as a subscription product then the custom entity is created. 我们输入一个订单,如果该订单的产品已定义为订阅产品,则将创建自定义实体。 The product can be either a single product or it can be a bundle. 该产品可以是单个产品,也可以是捆绑产品。 When the subscription ends I need to end the ability of the customer to continue to use the software. 订阅结束后,我需要终止客户继续使用该软件的能力。

I can read the product and I can determine if the product is a bundle by examining the attribute "productstructure". 我可以阅读该产品,并且可以通过检查属性“ productstructure”来确定该产品是否为捆绑销售商品。 How do I determine which products are included in the bundle? 如何确定捆绑包中包含哪些产品?

Thanks 谢谢

If you retrieve the product you can use "productstructure" to determine if it is a bundle. 如果检索产品,则可以使用“产品结构”来确定它是否为捆绑销售商品。 If the value is a 3 it is a bundle. 如果值为3,则为捆绑销售商品。

You can then query the "productassociation" table where the attribute "productid" equals the Id of the bundle. 然后,您可以查询“ productassociation”表,其中“ productid”属性等于捆绑商品的ID。

The attribute you need to retrieve from the "prodctassociation" table is "associatedproduct". 您需要从“产品关联”表中检索的属性是“关联产品”。 You then retrieve the product instance. 然后,您检索产品实例。

QueryExpression productBundleQuery = new QueryExpression();
productBundleQuery.Distinct = false;
productBundleQuery.EntityName = "productassociation";
productBundleQuery.ColumnSet = new ColumnSet("associatedproduct");
productBundleQuery.Criteria = new FilterExpression
{
     Conditions = { new ConditionExpression("productid", ConditionOperator.Equal, bundle.Id) }
};

EntityCollection productBundleCollection = _service.RetrieveMultiple(productBundleQuery);

foreach (Entity productAssociation in productBundleCollection.Entities)
{
    Entity product = _service.Retrieve("product", ((EntityReference)productAssociation["associatedproduct"]).Id, new ColumnSet("name", ...));

    Do something....
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM