Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algolia not updated on save #279

Closed
nitech opened this issue Oct 20, 2023 · 3 comments
Closed

Algolia not updated on save #279

nitech opened this issue Oct 20, 2023 · 3 comments

Comments

@nitech
Copy link

nitech commented Oct 20, 2023

When I save a product in Craft Commerce, the Algolia index is not updated. When I run a ./craft scout/index/refresh dev_products command the index is however updated.

Not sure when this happened, but possibly during one of the latest updates I did to this Craft instance. Running latest Craft, Commerce and Scout.

Defining indices thus:

'indices' => (new SitemoduleServiceService)->getIndicies()

    public function getIndicies(){
        $indicies = [];

        // environment always dev unless in production. So localdev, dev and stg becomes dev
        $env = "dev";
        if (getenv('ENVIRONMENT') == "prod") $env = "prod";

        // todo: add site 6 for Products and Product Families

        // products only relevant for site 5:
        $indicies[] = 
            \rias\scout\ScoutIndex::create("{$env}_products")
            ->elementType(\craft\commerce\elements\Product::class)
            ->criteria(function (\craft\commerce\elements\db\ProductQuery $query) use ($site, $productType) {
                $query->siteId = 5; // $site->id;
                return $query;
            })
            ->transformer(function (\craft\commerce\elements\Product $product) {
                return $this->transformProductData($product);
            });     
            
        // product families only relevant for site 5:
        $indicies[] = 
            \rias\scout\ScoutIndex::create("{$env}_product_families")
            ->elementType(\craft\elements\Category::class)
            ->criteria(function (\craft\elements\db\CategoryQuery $query) use ($site, $productType) {
                $query->siteId = 5; // $site->id;
                $query->group("productFamily");
                return $query;
            })
            ->transformer(function (\craft\elements\Category $category) {
                return $this->transformCategoryData($category);
            });              
            
        // entries on each site
        foreach (Craft::$app->getSites()->getAllSites() as $site) {
            $indicies[] = 
                \rias\scout\ScoutIndex::create("{$env}_{$site->handle}_entries")
                ->elementType(\craft\elements\Entry::class)
                ->criteria(function (\craft\elements\db\EntryQuery $query) use ($site) {
                    $query->siteId = $site->id;

                    // exclude a couple of section types 
                    $query->section("and, not people, not locations, not categoryIndex");
                    return $query;
                })
                ->transformer(function (\craft\elements\Entry $entry) {
                    return $this->transformEntryData($entry);
                });   
        }  

        return $indicies;
    }

Wondering whether it has something to do with me disabling a queue runner that was acting up after I had dome some updates to Craft

@janhenckens
Copy link
Member

Hey @nitech, could you confirm that site 5 is not your primary site and wether or not your are running with the queue option enabled?
And can you check if refreshing the index through the utility updates the product?

(this feels related to #266 but I'll leave this open for now)

@nitech
Copy link
Author

nitech commented Oct 23, 2023

Site 5 is not my primary site.
Queue option is enabled.
Refreshing through utility updates the product.
#266 fixed the problem

@janhenckens
Copy link
Member

Good to hear @nitech! I'll close your issue but feel free to reopen if need be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants