Jump to content

ProFields: Table field type issue


fliwire
 Share

Recommended Posts

My access to support form expired. sync_queue  is a "ProFields: Table field". 
Version: Table 0.2.3

// ready.php
$wire->addHookBefore(
    "Pages::saveReady(template=collection)",
    function (HookEvent $event) {
        $page = $event->arguments(0);

        if ($page->sync_add) {
            $collections = pages()->get("template=collections");
            $collections->of(false);

            foreach ($page->children() as $key => $product) {
                $queue = $collections->sync_queue("product={$product}, limit=1"); // always give 1 count can't check if already added.

                if (!$queue->count) {
                    $q = $collections->sync_queue->makeBlankItem();
                    $q->product = $product;
                    $q->date = time();

                    $collections->sync_queue->add($q);
                    $collections->save('sync_queue');
                }
            }

			// This works
            $home = pages("/");
            $http = new WireHttp();
            $response = $http->post($home->httpUrl, [
                "collection" => $page->id,
                "sync_add" => $page->sync_add,
            ]);
        }

        $page->sync_add = 0;
        $event->removeHook(null);
    }
);


// home.php
$collection = input("post", "collection", "int");
$sync_add = input("post", "sync_add", "int");
$collection = pages()->get("template=collection, id={$collection}");

if ($collection->id && $sync_add) {
	$products = $collection->children();
	$collections = pages()->get("template=collections");
	$collections->of(false);

	foreach ($products as $key => $product) {
		// Only add product one time
		$queue = $collections->sync_queue("product={$product}, limit=1"); // this works as expected

		if (!$queue->count) {
			$q = $collections->sync_queue->makeBlankItem();
			$q->product = $product;
			$q->date = time();

			$collections->sync_queue->add($q);
			$collections->save('sync_queue');
		}
	}
}
Link to comment
Share on other sites

Same issue:

$collections->sync_queue("product={$product}, limit=1");  // this not work in hook
$collections->sync_queue->find("product={$product}, limit=1"); // this works if pagination limit not enabled in settings.


 

Link to comment
Share on other sites

On 1/17/2024 at 1:36 PM, fliwire said:

Same issue:

$collections->sync_queue("product={$product}, limit=1");  // this not work in hook
$collections->sync_queue->find("product={$product}, limit=1"); // this works if pagination limit not enabled in settings.


 

I think you may have made the same mistake I did in that original post...

$collections->sync_queue("product={$product}, limit=1");  // this not work in hook

should be:

$collections->sync_queue->find("product={$product}, limit=1");  // this not work in hook

(find missing in the top one).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...