concretecms-community-store / community_store_stripe_checkout

Stripe Checkout payment add-on for Community Store for Concrete CMS
MIT License
1 stars 1 forks source link

Question: Checkout complete page get category #7

Open madesimplemedia opened 4 years ago

madesimplemedia commented 4 years ago

Hi,

On the checkout complete page I am using functions like $item->getSKU(), $item->getProductName() etc. to populate Google Analytics with data when someone completes a purchase.

Is there a way of getting the categories that a product is under?

Thanks Dave

Mesuva commented 4 years ago

You could try something like

$product = $item->getProductObject();

if ($product) {
    $locationPages = $product->getLocationPages();

    foreach ($locationPages as $location) {
        if ($location) {
            $locationpage = Page::getByID($location->getCollectionID());
            if ($locationpage) {
                echo $locationpage->getCollectionName();  // or do whatever you want with the category page
            }
        }
    }
}
madesimplemedia commented 4 years ago

Thanks that's great, got it working nicely.