尝试在orocommerce中创建自定义块类型,但我得到:无法加载块类型" product_variants"。

时间:2017-09-15 15:04:59

标签: php symfony symfony-2.1 orocrm orocommerce

尝试在orocommerce中创建自定义块类型,但我得到:无法加载块类型" product_variants"。

我在中创建了block_types yml文件 资源/配置/ block_types.yml

  services:
       xngage_product.layout.block_type.product_variants:
       parent: oro_layout.block_type.abstract_configurable_container
       calls:
        - [setOptionsConfig, [{variants: {required: true}}]]
        - [setName, ['product_variants']]
    tags:
         - { name: layout.block_type, alias: product_variants }


xngage_product.layout.block_type_extension.product_variants:
    class: Xngage\ProductBundle\Layout\Extension\ProductVariantsExtension
    tags:
        - { name: layout.block_type_extension, alias: product_variants }

并在Resources / layouts / xngage_theme / oro_product_frontend_product_view / configure_product.yml中为configure产品创建布局

layout:
imports:
    - oro_product_view

actions:
    - '@setBlockTheme':
        themes: 'configurable_product.html.twig'

    - '@add':
        id: product_variants
        blockType: product_variants
        parentId: product_specification_container
        siblingId: product_specification
        options:
            variants: '=data["product_variants"].getVariants(data["product"])'

conditions: 'context["product_type"] == "simple"'

请找到任何遗漏的步骤?

2 个答案:

答案 0 :(得分:2)

您是否在容器上注册了Resources/config/block_types.yml? 注册示例可以在https://github.com/orocommerce/orocommerce/blob/master/src/Oro/Bundle/CMSBundle/DependencyInjection/OroCMSExtension.php#L25

找到

答案 1 :(得分:0)

因此,使用Oro布局系统,您可以基于块创建自定义窗口小部件,因此负责该类的父类是Oro \ Bundle \ LayoutBundle \ Layout \ Block \ Type \ ConfigurableType,或者您可以按父对象基于容器创建自定义窗口小部件oro_layout.block_type.abstract_configurable或

oro_layout.block_type.abstract_configurable_container:
    oro_layout.block_type.abstract_configurable:
        abstract: true
        class: Oro\Bundle\LayoutBundle\Layout\Block\Type\ConfigurableType
    oro_layout.block_type.abstract_configurable_container:
        abstract: true
        parent: oro_layout.block_type.abstract_configurable
        calls:
            - [setParent, ['container']]

在内部创建block_types.yml Ibnab / Bundle / CustomWidgetBundle / Resources / config / block_types.yml并填写:

ibnab_custom_widget.layout.type.product:
    parent:  oro_layout.block_type.abstract_configurable
    calls:
        - [setOptionsConfig, [{product_id: {}}]]
        - [setName, ['ibnab_custom_widget_product']]

注意不要忘记在DependencyInjection / CustomWidgetExtension中加载block_types.yml,例如:

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('block_types.yml');

这里您添加了一个基于块小部件的自定义小部件,该小部件能够接受并选择product_id,您可以添加例如是必需的

- [setOptionsConfig, [{product_id: {required: true}}]]

在布局处理程序oro_product_frontend_product_view(该文件夹中包含产品页面视图的路由名称,当您在“产品详细信息”页面上时会很好地发送该文件夹),因此您可以使用以下示例填充layout.yml:

layout:
    actions:
        - '@setBlockTheme':
            themes: 'CustomWidgetBundle:layouts:blank/oro_product_frontend_product_view/layout.html.twig' 
        - '@add':
            id:  ibnab_custom_widget_product_direct
            parentId: product_view_primary_container
            blockType:  ibnab_custom_widget_product
            prepend: true
            options:
                product_id: '=data["product"].getId()'

现在您可以在您的layout.twig中使用带有此选项product_id的内部

完整课程OroCommerce Custom widget type based on block or container