Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Just a quick question (hopefully),
I'm having to work on an old, basic ecommerce site I built years ago. Ecommerce is definitely not my speciality!

I have successfully managed to set up some location based shipping on the cart level, modifying the cart_ex file (I found the solution here on the forum - thanks!).

However, I'm encountering a problem. In addition to this, I'm trying to add a discount based on the number of items in the cart. In the cart/config file, I've modified the following rule (line 78) - $pp['discount_by_quantity_ordered'] = '[ 1=5 | 2=10 ]'; So if 2 items are ordered - there should be a £5 discount, and if 3+ are ordered, a £10 discount.

Nothing is happening at checkout though. The code in the checkout to display the discount is directly from the cart example as far as I can remember <cms:if "<cms:pp_discount />">show discount stuff</cms:if> pp_discount has no value when I display it though - so obviosuly nothing is happening.

Is there something else I need to do to activate the discount? I've never really dealt with discounts before - I must be missing something obvious!
Thanks in advance,
ewanmc
Assuming you have renamed the 'config.example.php' file to 'config.php' and added the $pp['discount_by_quantity_ordered'] = '[ 1=5 | 2=10 ]'; line in it, I'd expect it to work.

Perhaps the customization you did in cart_ex.php are messing up things a bit? Please try commenting out your code in cart_ex.php and see if the default discount gets calculated as expected.
Hi KK,
As I'm sure you know - sometimes it just takes someone else to have a look. I tried what you suggested, but it still didn't work. So the next step was to scrap the cart_ex.php file completely - and start again from the example file. I added both the custom stuff, and the discount rule - it worked perfectly! I must have broken something somewhere...
Thanks as ever for your help KK :)
You are welcome :) I am glad it is working now.
Hello,

I'm currently having the same problem with the discount scale, I'm using the original cart_ex.php file for calculations.

Dump method, when invoked in my cart file, displays the discount_scale variable, but no line_discount or orig_price.
Code: Select all
pp_cart_items
line_id: ef58326b8fd27e7ad49c0aa2bca667c9
id: 15
name: test
title: Test product
link: https://cpa.aesir.tv/shop.php?p=15
price: 20
quantity: 25
line_total: 500
requires_shipping: 0
skip_line_total: 0
product_thumb: https://cpa.aesir.tv/midgard/uploads/image/products/element-thumb-example.jpg
discount_scale: [ 5=2 | 10=3 ]%


Here is my code in shop.php (clonable template where the products are added:
Code: Select all
<?php require_once( 'midgard/cms.php' ); ?>
<cms:template title="Produkty" icon="cart" parent="_shop_" order="0" clonable="1" dynamic_folders="1" folder_masterpage='shop_folders.php'>
    <cms:editable type="row" name="title_group" label="Ustawienia główne" collapsed="0" order="0" />
    <cms:each k_supported_langs as='lang' key='lc'>
        <cms:if lc != 'en'>
            <cms:editable type="text" name="title_<cms:show lc />" label="Tytuł (<cms:show lc />)" group="title_group" />
        </cms:if>
    </cms:each>

    <cms:editable type="group" name="media_group" label="Media" collapsed="0" order="1">
        <cms:editable type="image" name="pp_product_thumb" label="Miniatura" desc="Preferowana rozdzielczość: 400x436px" show_preview="1" preview_height="80" width="400" height="436" crop="1" required="1" />
        <cms:repeatable name="image_gallery" label="Galeria zdjęć">
            <cms:editable type="image" name="product_image" label="Zdjęcie - preferowana rozdzielczość: 679x600px" show_preview="1" preview_height="70" width="679" height="600" crop="1" />
        </cms:repeatable>
    </cms:editable>

    <cms:editable type="group" name="price_group" label="Ceny" collapsed="0" order="2">
        <cms:editable type="text" name="pp_price" label="Cena produktu" desc='bez znaku waluty, do dwóch miejsc po przecinku' maxlength='10' required='1' search_type='decimal' validator='non_zero_decimal' width='150' order="0" />

        <cms:editable name='explain_discount_scale' type='message' order='3'>...</cms:editable>   

        <cms:editable name='pp_discount_scale' label='Ustawienia zakresów cen:' type='text' group='group_price' validator='regex=/\[\[?([^\]]*)\](\]?)\s*(%?)/' order='4' />

        <cms:editable type="message" name="discount_disclaimer_info" order="4" >
            Poniższe ustawienia służą do wyświetlenia przedziałów w sposób czytelny dla klienta sklepu. Wprowadzenie tu danych nie wpłynie na cenę - w tym celu należy ustawić pole <b>Ustawienia zakresów cen</b>.
        </cms:editable>
        <cms:repeatable name="discount_disclaimer" order="5" >
            <cms:editable type="text" name="discount_span" label="Przedział od...do (np. 1-10)" col_width="40" />
            <cms:editable type="text" name="price" label="Cena jednostkowa" col_width="150" />
        </cms:repeatable>
    </cms:editable>

    <cms:editable type="group" name="variants_group" label="Opcje produktu" collapsed="0" order="3">
        <cms:editable name='explain_options'  type='message'>...</cms:editable>   
       
        <cms:editable name='pp_options' label='Ustawienia wariantów:' height='130' type='textarea' group='group_variants' />
    </cms:editable>

    <cms:editable type="group" name="product_description_group" label="Opis produktu" collapsed="0" order="4">
        <cms:mosaic name="product_extras" label="Dodatkowe informacje" order="5">
            <cms:tile name="extras_text" label="Blok tekstowy">
                <cms:editable type="text" name="extras_tab_label_en" label="Tytuł sekcji (en)" order="1" />
                <cms:editable type="text" name="extras_tab_label_pl" label="Tytuł sekcji (pl)" order="1" />
                <cms:editable type="text" name="extras_tab_label_de" label="Tytuł sekcji (de)" order="1" />
                <cms:editable type="richtext" name="extras_text_content_en" label="Treść (en)" order="2" />
                <cms:editable type="richtext" name="extras_text_content_pl" label="Treść (pl)" order="2" />
                <cms:editable type="richtext" name="extras_text_content_de" label="Treść (de)" order="2" />
            </cms:tile>
            <cms:tile name="extras_list" label="Lista (np. specyfikacji)">
                <cms:editable type="text" name="extras_tab_label_en" label="Tytuł sekcji (en)" order="1" />
                <cms:editable type="text" name="extras_tab_label_pl" label="Tytuł sekcji (pl)" order="1" />
                <cms:editable type="text" name="extras_tab_label_de" label="Tytuł sekcji (de)" order="1" />
                <cms:repeatable name="extras_list_rows" label="Pozycje" stacked_layout="1">
                    <cms:editable type="text" name="extras_list_label_en" label="Nazwa pozycji (en)" order="1" />
                    <cms:editable type="text" name="extras_list_label_pl" label="Nazwa pozycji (pl)" order="1" />
                    <cms:editable type="text" name="extras_list_label_de" label="Nazwa pozycji (de)" order="1" />
                    <cms:editable type="text" name="extras_list_content_en" label="Treść (en)" order="2" />
                    <cms:editable type="text" name="extras_list_content_pl" label="Treść (pl). Opcjonalne - puste pole wyświetli tekst EN" order="2" />
                    <cms:editable type="text" name="extras_list_content_de" label="Treść (de). Opcjonalne - puste pole wyświetli tekst EN" order="2" />
                </cms:repeatable>
            </cms:tile>
        </cms:mosaic>
    </cms:editable>

    <cms:each k_supported_langs as='lang' key='lc'>
        <cms:editable type="row" name="product_desc_row_<cms:show lc />" label="Opis (<cms:show lc />)" order=k_count group="product_description_group" collapsed="<cms:if lc='en'>0<cms:else/>1</cms:if>">
            <cms:editable type="richtext" name="product_description_<cms:show lc />" label="Opis produktu" order="1" class="col-md-12" />
        </cms:editable>
    </cms:each>

    <cms:config_form_view>
        <cms:field 'k_page_title' label="Tytuł (en)" group="title_group" order="0" />
        <cms:field 'k_page_name' group="title_group" order="4" class="col-md-7" />
        <cms:field 'k_page_folder_id' group="title_group" order="3" />
    </cms:config_form_view>
</cms:template>

<cms:if k_is_page >
    <cms:embed 'shop-item.html' />
<cms:else />
    <cms:embed 'shop-list.html' />
</cms:if>

<?php COUCH::invoke(); ?>


Here is the product snippet:
Code: Select all
<cms:pp_product_form class="cart-form">
                                <div class="product-variants">
                                    <div class="product-variant-group">
                                        <cms:pp_product_options>
                                            <span><cms:show option_name />:</span>
                                            <cms:pp_option_values />
                                        </cms:pp_product_options>
                                    </div>
                                </div>
                                <!-- price -->
                                <div class="product-price">
                                    <h3><cms:get_field "your_price_<cms:show k_lang />" masterpage="translations.php" />:
                                        <span><cms:number_format pp_price /> €</span>
                                    </h3>
                                </div>
                                <!-- add to cart -->                           
                                <nav class="product-actions">
                                    <div class="cartitem-counter">
                                        <button type="button" class="cartitem-sub">-</button>
                                        <input type="number" id="main-qty" name="qty" class="form-control" value="1">
                                        <button type="button" class="cartitem-add">+</button>
                                    </div>
                                    <button type="submit" class="btn btn-primary addcartbutton">
                                        <svg><use xlink:href="./img/sprite.svg#cart"></use></svg>
                                        <span><cms:get_field "add_cart_<cms:show k_lang />" masterpage="translations.php" /></span>
                                    </button>                         
                                </nav>
                            </cms:pp_product_form>


And here is the cart product listing (for now - I haven't yet implemented the cart summary, as I've encountered quantity discount error and spent an evening trying to fix it ;)
Code: Select all
<cms:pp_cart_items>
                                            <!-- cart item -->
                                            <tr>
                                                <td class="item-image"><img src="<cms:show product_thumb />" class="img-fluid"></td>
                                                <td class="item-name">
                                                    <a href="<cms:show link />" class="product-title">
                                                        <cms:if k_lang = 'en'>
                                                            <cms:show title />
                                                        <cms:else />
                                                            <cms:pages masterpage="shop.php" name=name >
                                                                <cms:get "title_<cms:show k_lang />" />
                                                            </cms:pages>
                                                        </cms:if>
                                                    </a>
                                                    <span class="product-option"><cms:pp_selected_options separator=' | ' /></span>
                                                   
                                                    <cms:dump />
                                                </td>
                                                <td class="item-price text-center d-none d-md-table-cell">
                                                    <span class="item-unit-price"><cms:number_format price /> €</span>
                                                </td>
                                                <td class="item-qty">
                                                    <nav class="cartitem-counter">
                                                        <button type="button" class="cartitem-sub">-</button>
                                                        <input type="number" id="" name="qty[<cms:show line_id />]" class="form-control" value="<cms:show quantity />">
                                                        <button type="button" class="cartitem-add">+</button>
                                                    </nav>
                                                </td>
                                                <td class="item-subtotal text-center d-none d-md-table-cell">
                                                    <span class="item-total-price"><cms:number_format line_total /> €</span>
                                                </td>
                                                <td class="item-delbtn">
                                                    <a href="<cms:pp_remove_item_link />" class="item-delete">×</a>
                                                </td>
                                            </tr>
                                            <!-- END cart item -->
                                        </cms:pp_cart_items>


Thank You in advance!
Hi - sorry to bother you, as it seems to work now :D it kind of "fixed itself", so maybe I had some old cookies or outdated cache caused some problem :D

Best regards,
TheV
6 posts Page 1 of 1
cron