I have a plugin that is listening to the
In my product settings, in the "Automatic SKU Format" field I have:
That way I am always working the main product title.
For the SKU, I want to only use the first initial of each word - so I am doing this from my plugin:
... $default_sku = $event->params['product']->defaultVariant->sku; $expr = '/(?<=\s|^)[a-z]/i'; preg_match_all($expr, $default_sku, $matches); $sku = strtoupper(implode('', $matches)); ... error_log((craft()->config->get('devMode')) ? 'SKU: ' . $sku : '');
Let's say I have "My Super Product" as the title. The above is generating this: MSP
But, now I'm not sure how to go back and re-save the product.
Do I need to re-find the product and then set the
defaultSku and then re-save it? Not sure how to proceed.
Thank you for any suggestions!