Magento - клонируйте блок product.info в боковую панель и включите данные условного типа продукта - PullRequest
1 голос
/ 15 августа 2011

Что мне нужно: блоки «addtocart» и «product_type_data» в «правильном» разделе, а не в «content»

Что я пробовал: я пытался создать новый файл дляблок с именем sidebar.phtml, а затем вставил его в мой local.xml, который находится внутри моей темы (файл .xml отлично работает для других блоков)

<default>

        <reference name="right">
            <action method="unsetChildren"></action><!-- remove all blocks -->

            <block type="catalog/product_view" name="product.sidebar" template="catalog/product/view/sidebar.phtml">

                <block type="catalog/product_view" name="product.sidebar.options.wrapper" as="product_options_wrapper" template="catalog/product/view/options/wrapper.phtml" translate="label">
                    <label>Info Column Options Wrapper</label>
                    <block type="core/template" name="options_js" template="catalog/product/view/options/js.phtml"/>
                    <block type="catalog/product_view_options" name="product.sidebar.options" as="product_options" template="catalog/product/view/options.phtml">
                        <action method="addOptionRenderer"><type>text</type><block>catalog/product_view_options_type_text</block><template>catalog/product/view/options/type/text.phtml</template></action>
                        <action method="addOptionRenderer"><type>file</type><block>catalog/product_view_options_type_file</block><template>catalog/product/view/options/type/file.phtml</template></action>
                        <action method="addOptionRenderer"><type>select</type><block>catalog/product_view_options_type_select</block><template>catalog/product/view/options/type/select.phtml</template></action>
                        <action method="addOptionRenderer"><type>date</type><block>catalog/product_view_options_type_date</block><template>catalog/product/view/options/type/date.phtml</template></action>
                </block>
                        <block type="core/html_calendar" name="html_calendar" as="html_calendar" template="page/js/calendar.phtml"/>
                    </block>
                <block type="catalog/product_view" name="product.sidebar.options.wrapper.bottom" as="product_options_wrapper_bottom" template="catalog/product/view/options/wrapper/bottom.phtml" translate="label">
                    <label>Bottom Block Options Wrapper</label>
                    <action method="insert"><block>product.tierprices</block></action>
                    <block type="catalog/product_view" name="product.clone_prices" as="prices" template="catalog/product/view/price_clone.phtml"/>
                    <action method="append"><block>product.sidebar.addtocart</block></action>
                    <action method="append"><block>product.sidebar.addto</block></action>
                </block>

                <block type="core/template_facade" name="product.sidebar.container1" as="container1">
                    <action method="setDataByKey"><key>alias_in_layout</key><value>container1</value></action>
                    <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
                    <action method="append"><block>product.sidebar.options.wrapper</block></action>
                    <action method="append"><block>product.sidebar.options.wrapper.bottom</block></action>
                </block>
                <block type="core/template_facade" name="product.sidebar.container2" as="container2">
                    <action method="setDataByKey"><key>alias_in_layout</key><value>container2</value></action>
                    <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
                    <action method="append"><block>product.sidebar.options.wrapper</block></action>
                    <action method="append"><block>product.sidebar.options.wrapper.bottom</block></action>
                </block>
                <action method="unsetCallChild"><child>container1</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
                <action method="unsetCallChild"><child>container2</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>

            </block>

        </reference>


    </default>

<!--
    Additional block dependant on product type
    -->
    <PRODUCT_TYPE_simple translate="label" module="catalog">
        <label>Catalog Product View (Simple)</label>
        <reference name="product.sidebar">
            <block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data" template="catalog/product/view/type/default.phtml">
                <block type="core/text_list" name="product.info.simple.extra" as="product_type_data_extra" translate="label">
                    <label>Product Extra Info</label>
                </block>
            </block>
        </reference>
    </PRODUCT_TYPE_simple>
    <PRODUCT_TYPE_configurable translate="label" module="catalog">
        <label>Catalog Product View (Configurable)</label>
        <reference name="product.sidebar">
            <block type="catalog/product_view_type_configurable" name="product.info.configurable" as="product_type_data" template="catalog/product/view/type/default.phtml">
                <block type="core/text_list" name="product.info.configurable.extra" as="product_type_data_extra" translate="label">
                    <label>Product Extra Info</label>
                </block>
            </block>
        </reference>
        <reference name="product.sidebar.options.wrapper">
            <block type="catalog/product_view_type_configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="catalog/product/view/type/options/configurable.phtml"/>
        </reference>
    </PRODUCT_TYPE_configurable>
    <PRODUCT_TYPE_grouped translate="label" module="catalog">
        <label>Catalog Product View (Grouped)</label>
        <reference name="product.sidebar">
            <block type="catalog/product_view_type_grouped" name="product.info.grouped" as="product_type_data" template="catalog/product/view/type/grouped.phtml">
                <block type="core/text_list" name="product.info.grouped.extra" as="product_type_data_extra" translate="label">
                    <label>Product Extra Info</label>
                </block>
            </block>
        </reference>
    </PRODUCT_TYPE_grouped>
    <PRODUCT_TYPE_virtual translate="label" module="catalog">
        <label>Catalog Product View (Virtual)</label>
        <reference name="product.sidebar">
            <block type="catalog/product_view_type_virtual" name="product.info.virtual" as="product_type_data" template="catalog/product/view/type/default.phtml">
                <block type="core/text_list" name="product.info.virtual.extra" as="product_type_data_extra" translate="label">
                    <label>Product Extra Info</label>
                </block>
            </block>
        </reference>
    </PRODUCT_TYPE_virtual>

Это работает до некоторой степени, добавляет "блок addtocart "и оболочки параметров и т. д. на моей боковой панели, но не добавляет в него блоки" product_type_data ", поэтому я чувствую, что в этих условных тегах может быть что-то не так, но мои знания XML очень ограничены ...

Также мой файл sidebar.phtml выглядит так:

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>

    <!-- Product Type Options Start -->
            <?php echo $this->getChildHtml('product_type_data') ?>
        <!-- Product Type Options End -->

        <?php echo $this->getTierPriceHtml() ?>

        <!-- container1 -->
        <?php if ($_product->isSaleable() && $this->hasOptions()):?>
            <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
        <?php endif;?>

        <!-- container2 -->
        <?php if ($_product->isSaleable() && $this->hasOptions()):?>
            <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
        <?php endif;?>

Любая помощь будет очень полезна.

Очень ценится, Дэйв

1 Ответ

2 голосов
/ 06 мая 2012

Перейдите в catalog.xml и скопируйте

<block type="catalog/product_view" name="product.info.options.wrapper" as="product_options_wrapper" template="catalog/product/view/options/wrapper.phtml" translate="label">
                <label>Info Column Options Wrapper</label>
                <block type="core/template" name="options_js" template="catalog/product/view/options/js.phtml"/>
                <block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
                    <action method="addOptionRenderer"><type>text</type><block>catalog/product_view_options_type_text</block><template>catalog/product/view/options/type/text.phtml</template></action>
                    <action method="addOptionRenderer"><type>file</type><block>catalog/product_view_options_type_file</block><template>catalog/product/view/options/type/file.phtml</template></action>
                    <action method="addOptionRenderer"><type>select</type><block>catalog/product_view_options_type_select</block><template>catalog/product/view/options/type/select.phtml</template></action>
                    <action method="addOptionRenderer"><type>date</type><block>catalog/product_view_options_type_date</block><template>catalog/product/view/options/type/date.phtml</template></action>
            </block>
                    <block type="core/html_calendar" name="html_calendar" as="html_calendar" template="page/js/calendar.phtml"/>
                </block>
            <block type="catalog/product_view" name="product.info.options.wrapper.bottom" as="product_options_wrapper_bottom" template="catalog/product/view/options/wrapper/bottom.phtml" translate="label">
                <label>Bottom Block Options Wrapper</label>
                <action method="insert"><block>product.tierprices</block></action>
                <block type="catalog/product_view" name="product.clone_prices" as="prices" template="catalog/product/view/price_clone.phtml"/>
                <action method="append"><block>product.info.addtocart</block></action>
                <action method="append"><block>product.info.addto</block></action>
            </block>

и вставьте в

<reference name="right">


    HERE            

        <block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
    </reference>

Тогда будет выглядеть так:

<reference name="right">
                <block type="catalog/product_view" name="product.info.options.wrapper" as="product_options_wrapper" template="catalog/product/view/options/wrapper.phtml" translate="label">
                <label>Info Column Options Wrapper</label>
                <block type="core/template" name="options_js" template="catalog/product/view/options/js.phtml"/>
                <block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
                    <action method="addOptionRenderer"><type>text</type><block>catalog/product_view_options_type_text</block><template>catalog/product/view/options/type/text.phtml</template></action>
                    <action method="addOptionRenderer"><type>file</type><block>catalog/product_view_options_type_file</block><template>catalog/product/view/options/type/file.phtml</template></action>
                    <action method="addOptionRenderer"><type>select</type><block>catalog/product_view_options_type_select</block><template>catalog/product/view/options/type/select.phtml</template></action>
                    <action method="addOptionRenderer"><type>date</type><block>catalog/product_view_options_type_date</block><template>catalog/product/view/options/type/date.phtml</template></action>
            </block>
                    <block type="core/html_calendar" name="html_calendar" as="html_calendar" template="page/js/calendar.phtml"/>
                </block>
            <block type="catalog/product_view" name="product.info.options.wrapper.bottom" as="product_options_wrapper_bottom" template="catalog/product/view/options/wrapper/bottom.phtml" translate="label">
                <label>Bottom Block Options Wrapper</label>
                <action method="insert"><block>product.tierprices</block></action>
                <block type="catalog/product_view" name="product.clone_prices" as="prices" template="catalog/product/view/price_clone.phtml"/>
                <action method="append"><block>product.info.addtocart</block></action>
                <action method="append"><block>product.info.addto</block></action>
            </block>



        <block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
    </reference>

Наслаждайтесь!

...