Private Orders Shop in PrestaShop and thirty bees part 2: hide shopping options for visitors

In this second tutorial we will see how to prevent orders from non-registered customers, which is also necessary in case you applied the previous tutorial and are currently using a one page checkout.

Watch the screencast

Text Version

METHOD 1 – Selectively enabling catalog mode

If we don’t need to display prices to our visitors, the simplest and quickest way to proceed is by selectively enable catalog mode. Open classes/controller/FrontController.php, and locate the following string, inside the init method:

'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE') || (Group::isFeatureActive() && !(bool)Group::getCurrent()->show_prices),

Replace it with the following:

'PS_CATALOG_MODE' => $catalog_mode || (Group::isFeatureActive() && !(bool)Group::getCurrent()->show_prices),

We need to create that $catalog_mode variable of course, so let’s add this before the whole assign block:

$catalog_mode = (bool)Configuration::get('PS_CATALOG_MODE');
    $catalog_mode = true;

As you can see, we simply check if the customer id is set (that is, if the user is logged in) and if so, we set catalog mode to true, effectively disabling all cart functionalities. This however left us with a useless cart block, and without prices. Let’s see how to handle it differently then!

METHOD 2 – Selectively disable products

I will create an override for this one, so in override/classes, let’s create a new file named Product.php.

Let’s open it up, and copy over the construct method from the core product class. Get rid of everything inside it, and simply add the following:

Class Product extends ProductCore
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
        parent::__construct($id_product, $id_lang, $id_shop);

            $this->available_for_order = false;

This will take care of the product page. Now for the product list, the property is set elsewhere, and specifically in the getProductProperties method (without s). Copy the whole method from the original class again, but this time leave the content, and just append the following code at the end, right before self::$producPropertiesCache[$cache_key] = $row;

    $row['available_for_order'] = false;

And that’s all we need! Since we created a new override, remember it’s necessary to erase cache/class_index.php in order for the changes to take place.

You like the tuts and want to say "thank you"? Well, you can always feel free to donate:

Store Top Sales

You like the tuts and want to say "thank you"? Well, you can always feel free to donate: