1

I've been working on a new modal design to be AB tested against the old version. However, I don't want to dive into third party AB testing code/frameworks so I have opted for a simpler approach.

Although simple, my if statement is not working correctly for some reason.

Here's the code:

$helper = $this->getHelper();
$items = $helper->getWishlistItemCollection(null, true);
$param = isset($_GET['version']);
?>
<?php if ($param == "a") : ?>
<?php if (true || $helper->getItemCount() > 0): ?>
<div class="block block-wishlist guest-wishlist" data-bind="scope: 'wishlist'">
    <img class="samplebox" src="<?php echo $this->getViewFileUrl('images/MMB-box-Latest-2019.png'); ?>" />
    <div id="freesamples-alert" style="display: none;"></div>
    <div class="block-content">
        <ol class="product-items" id="wishlist-sidebar">
            <?php foreach ($items as $item) : ?>
                <li class="product-item" id="item_<?php echo $item->getId() ?>">
                    <div class="product-item-info">
                        <a class="product-item-photo" href="<?php echo $helper->getProductUrl($item) ?>" title="<?php echo $item->getName() ?>">
                            <div class="product-image-container">
                                <div class="product-image-wrapper">
                                    <img class="product-image-photo" data-bind="attr: {src: src, alt: alt}" src="<?php echo $helper->getImageUrl($item) ?>" alt="<?php echo $item->getName() ?>">
                                </div>
                            </div>
                        </a>
                        <div class="product-item-details">
                            <strong class="product-item-name">
                                <a class="product-item-link" href="<?php echo $helper->getProductUrl($item) ?>">
                                    <span data-bind="text: product_name"><?php echo $item->getName() ?></span>
                                </a>
                            </strong><br />
                            <a href="#" data-wish-role="remove" data-item-id="<?php echo $item->getId() ?>" title="<?php echo __('Remove This Item') ?>" class="btn-remove action delete">Remove
                            </a>

                            <div class="product-item-actions"></div>
                        </div>
                    </div>
                </li>
            <?php endforeach; ?>
        </ol>
        <div class="block-footer">
            <div class="wishlist-process">
                <img src="<?php echo $this->getViewFileUrl('images/Group 31.png'); ?>" class="img-fluid" />
                <p>Up to 20 real fabric or wooden samples!</p>
            </div>
            <div class="wishlist-process">
                <img src="<?php echo $this->getViewFileUrl('images/Group 11.png'); ?>" class="img-fluid" />
                <p>Measuring Guides for all common windows.</p>
            </div>
            <div class="wishlist-process">
                <img src="<?php echo $this->getViewFileUrl('images/Combined Shape.png'); ?>" class="img-fluid" />
                <p>All delivered directly to your door, for free!</p>
            </div>
            <div class="actions">
                <a href="/freesamples/index/index/" class="btn">Order your free sample pack now</a>
                <a href="#" class="btn no-bg" id="exit">Continue Browsing</a>
            </div>
        </div>
    </div>
</div>
<?php endif; ?>
<?php elseif ($param !== "a") : ?>
<?php if(true || $helper->getItemCount() > 0) : ?>
<div class="block block-wishlist guest-wishlist" data-bind="scope: 'wishlist'">
    <div id="freesamples-alert" style="display: none;"></div>
    <div class="block-content">
        <ol class="product-items" id="wishlist-sidebar">
            <?php foreach ($items as $item) : ?>
                <li class="product-item" id="item_<?php echo $item->getId() ?>">
                    <div class="product-item-info">
                        <a class="product-item-photo" href="<?php echo $helper->getProductUrl($item) ?>" title="<?php echo $item->getName() ?>">
                            <div class="product-image-container">
                                <div class="product-image-wrapper">
                                    <img class="product-image-photo" data-bind="attr: {src: src, alt: alt}" src="<?php echo $helper->getImageUrl($item) ?>" alt="<?php echo $item->getName() ?>">
                                </div>
                            </div>
                        </a>
                        <div class="product-item-details">
                            <strong class="product-item-name">
                                <a class="product-item-link" href="<?php echo $helper->getProductUrl($item) ?>">
                                    <span data-bind="text: product_name"><?php echo $item->getName() ?></span>
                                </a>
                            </strong><br />
                            <a href="#" data-wish-role="remove" data-item-id="<?php echo $item->getId() ?>" title="<?php echo __('Remove This Item') ?>" class="btn-remove action delete">Remove
                            </a>

                            <div class="product-item-actions"></div>
                        </div>
                    </div>
                </li>
            <?php endforeach; ?>
        </ol>
        <div class="block-notes">
            <p>You can order up to 20 free samples to be delivered to your door, just add them to your wishlist.</p>
        </div>
    </div>
</div>
<?php endif; ?>

The expected result is when the URL has the parameter ?version=a then it displays the new version of the modal, but if the parameter is not equal to "a" then it displays the old version.

The result I'm getting is that it ignores whether the parameter is set or not, and just displays the old version.


EDIT

So I've done some more testing and from what I think may be happening is the modal does not load until the page has loaded. So essentially PHP isn't able to get the parameter until the modal is opened.

Is there a way around this?

1

$param = isset($_GET['version']); will always evaluate to true or false and you are comapring true|false with the string a.

I think you mean

$param = isset($_GET['version']) ? $_GET['version'] : null;
  • Thank you for your answer, I have tried implementing your solution but unfortunately it's still not working. It still displays the old version despite the parameters existing and being equal to "a". – Howliee Sep 13 at 11:36
  • could also be related to cache. Maybe the block is cached and it does not matter what you add in the url, you get the value from cache. – Marius Sep 13 at 11:44
  • I've tried clearing the cache, setup:upgrade and setup:static-content:deploy but nothing seems to be working. Such a pain been stuck with this issue for a few days now. – Howliee Sep 13 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.