After migration from Magento1 Enterprise to Magento2 Commerce I need to programmatically refresh the customer segments
1 Answer
I created this method to be used by our post migration command:
public function refreshSegments()
{
$segments = $this->customerSegmentCollection->create();
/** @var \Magento\CustomerSegment\Model\Segment $segment */
foreach ($segments as $segment) {
echo "Updating: ".$segment->getName()."\r\n";
$segment->matchCustomers();
}
}