Jump to content

Repater (Matrix) items added twice


DrQuincy
 Share

Recommended Posts

I'm sure this will be something really simple but I am adding repeaters items to a Pro Fields Matrix and each item gets added twice (they are identical). The code definitely only runs once and there are no duplicate items in $basketTable. Am I doing anything wrong?

Thanks.

(Irrelevant code has been removed)

$p = new \ProcessWire\Page();

$p->template = 'account-order';
$p->name 	 = $orderReference;

$p->of(false);

foreach ($basketTable as $tableItem) {
	
	if (isset($tableItem['type']) === true) {
		
		if ($tableItem['type'] == 'typeface-trial') {
			
			$orderDownload  						= $p->orderDownloads->getNew();
			
			$orderDownload->repeater_matrix_type 	= 1;
			$orderDownload->orderTypeface 			= $tableItem['id'];
			
			$orderDownload->save();
			$p->orderDownloads->add($orderDownload);
			
		}
		
		if ($tableItem['type'] == 'typeface-weight') {
			
			$orderDownload  						= $p->orderDownloads->getNew();
			
			$orderDownload->repeater_matrix_type 	= 2;
			$orderDownload->orderDownloadsWeight	= $tableItem['weight-id'];
			$orderDownload->orderDownloadsLicense	= $tableItem['license-id'];
			
			$orderDownload->save();
			$p->orderDownloads->add($orderDownload);
			
		}
		
		if ($tableItem['type'] == 'typeface-bundle') {
			
			$orderDownload  						= $p->orderDownloads->getNew();
			
			$orderDownload->repeater_matrix_type 	= 3;
			$orderDownload->orderDownloadsBundle	= $tableItem['bundle-id'];
			$orderDownload->orderDownloadsLicense	= $tableItem['license-id'];
			
			$orderDownload->save();
			$p->orderDownloads->add($orderDownload);
			
		}
		
	}
	
}

$p->save();

I thought the process is to called getNew(), set the properties, save it and then add it to the page and save that — which I'm doing.

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...