Moqui开发Rest Api-2

产品页开发

有了首页,开发一个包含各目录的产品页,也就是小程序里的分类。Moqui可以设置多级目录。网易严选的小程序是三层目录,我们仅安排两层。子目录可以归属于几个不同的你目录,比如婴儿衣服,即可以放在服装下,还可以放在母婴下。

<service verb="get" noun="StoreProducts">
        <in-parameters>
            <parameter name="productStoreId" required="true"/>
        </in-parameters>
        <out-parameters>
            <parameter name="productCategories" type="List"/>
         </out-parameters>
        <actions>         
            <entity-find entity-name="mantle.product.store.ProductStoreCategory" list="productsCategoryList" cache="true">
                <date-filter/>
                <econdition field-name="productStoreId"/>
                <econdition field-name="storeCategoryTypeEnumId" value="PsctBrowseRoot"/>
                <order-by field-name="sequenceNum,-fromDate"/>
            </entity-find>

            <set field="productCategories" from="[]"/>

            <iterate list="productsCategoryList" entry="productsCategory">
                <entity-find-one entity-name="mantle.product.category.ProductCategory" value-field="productCategory" cache="true">
                    <field-map field-name="productCategoryId" from="productsCategory.productCategoryId"/>
                </entity-find-one>

                <if condition="productCategory != null">
                    <set field="CategoryImageUrl" from="null"/>
                    <entity-find-one entity-name="mantle.product.category.ProductCategoryContent" value-field="CategoryImageUrl" cache="true">
                        <date-filter/>
                        <field-map field-name="productCategoryId" from="productsCategory.productCategoryId"/>
                        <field-map field-name="categoryContentTypeEnumId" value="PcctImageUrl"/>
                    </entity-find-one>
                    <set field="rollupList" from="null"/>
                    <entity-find entity-name="mantle.product.category.ProductCategoryRollup" list="rollupList" cache="true">
                        <date-filter/><econdition field-name="parentProductCategoryId" from="productsCategory.productCategoryId"/>
                        <order-by field-name="sequenceNum,-fromDate"/>
                    </entity-find>
                    <set field="subCategoryList" from="[]"/>
                    <iterate list="rollupList" entry="rollup">
                        <entity-find-one entity-name="mantle.product.category.ProductCategory" value-field="subProductCategory" cache="true">
                                 <field-map field-name="productCategoryId" from="rollup.productCategoryId"/></entity-find-one>

                        <set field="Image" from="null"/>
                        <entity-find-one entity-name="mantle.product.category.ProductCategoryContent" value-field="Image" cache="true">
                                 <date-filter/>
                                 <field-map field-name="productCategoryId" from="rollup.productCategoryId"/>
                                 <field-map field-name="categoryContentTypeEnumId" value="PcctImageUrl"/>
                        </entity-find-one>

                        <script>subCategoryList.add([productCategoryId:subProductCategory.productCategoryId, pseudoId:subProductCategory.pseudoId,
                            categoryName:subProductCategory.categoryName, description:subProductCategory.description,
                            categoryImageUrl:Image?.contentLocation, sequenceNum:rollup.sequenceNum])
                        </script>
                    </iterate>
              
                    <script>
                        productCategories.add([productCategoryId:productCategory.productCategoryId, pseudoId:productCategory.pseudoId,
                        categoryName:productCategory.categoryName, description:productCategory.description,
                        categoryImageUrl:CategoryImageUrl?.contentLocation, sequenceNum:productsCategory.sequenceNum, subCategoryList:subCategoryList])
                   </script>
               </if>
            </iterate>
        </actions>
    </service>

代码很容易看懂,首先用storeCategoryTypeEnumId找出产品父目录,遍历父目录、子目录,找出每个子目录的缩略图。

最后小程序的展示,参考网易严选小程序的分类,要做成那样的三层目录,再嵌套一层就是了。

其它各目录下的产品,和点击产品后的产品详情页,参考PopRestStore的ProductServices里的实现就是了。

如果要分页,参照PopRestStore的ProductServices里search products 或get categoryProducts里的productListCount, productListPageIndex, productListPageSize, productListPageMaxIndex, productListPageRangeLow, productListPageRangeHigh就是。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值