Question

First, thanks for the help.

I've written code to display content based on the current path of a product.

If user lands on a product in category path "999" (index.php?route=product/product&path=999) "EXAMPLE TEXT" will appear. However, I'm having a hard time adding in a "wildcard" method so any categories starting with "999" for example (index.php?route=product/product&path=999_1_49) - I'm not too great with PHP so any help will be great!

Thanks, here is the code I was using.

<?php if (!isset($this->request->get['path']) || $this->request->get['path'] == '999') { ?>EXAMPLE TEST <?php } ?> 

UPDATE

I have identified a "bug". First - this seems to work fine with SEO enabled as the path is still the same, however, when SEO is enabled, customers are able to view products outside of the category they are assigned to. For example, normally a customer would click on the category "Acura" then "Acura CL" and the URL would be "http://www.XYZ.com//Acura%20Performance%20Chips/Acura%20CL" where the path would be "999" (for example). When using the code above, the content within the PHP tags will be displayed. However, when SEO is enabled, the customer can also find the product directly via the URL "http://www.XYZ.com/Acura%CL". If the customer views the product via this URL the content within the PHP tags is visible, not hidden.

In short, it seems as if the content is being displayed when no path is assigned (viewing the product directly versus viewing through its parent category). I'm lost how to fix this, please advise. This is a shop that is heavily modified so any extension recommendations will be ignored as we're not willing to take the risk of installing modifications that could potentially cause further issues.

Was it helpful?

Solution

if (!isset($this->request->get['path']) || substr($this->request->get['path'],0,3) == '999') ...

OTHER TIPS

Firstly, your first 'bug' is because of the first condition check.

!isset($this->request->get['path'])

If no path is present, the content will be displayed.



Because you want your message to be displayed even when a product is accessed directly, the above will not work. Instead you'll have to pull the category ID's that product belongs too from the DB, then do a check.

Something like so:

    <?php $category_results = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$this->request->get['product_id'] . "'");  ?>
    <?php foreach ($category_results->rows as $category) { ?>
    <?php if ($category['category_id'] == '999') { ?>
    /// EXAMPLE TEST \\\
    <?php break; ?>
    <?php } ?>
    <?php } ?>

Ideally though, this sort of code should be kept out of the view file and placed within the controller, then just referenced within the view file.



Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top