Skip to content

Instantly share code, notes, and snippets.

@supercid
Created June 19, 2018 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supercid/115fc84377e925fd50e54f754caf45fa to your computer and use it in GitHub Desktop.
Save supercid/115fc84377e925fd50e54f754caf45fa to your computer and use it in GitHub Desktop.
Explode tags comma delimited
<?php
/**
* Overridden product meta data model.
* This model is used as the data source when generating the tagging elements
* on the product page, and when making server-to-server API calls to Nosto.
*/
class My_Nosto_Model_Meta_Product extends Nosto_Tagging_Model_Meta_Product
{
/**
* @inheritdoc
*/
public function loadData (Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store = null)
{
if (is_null($store)) {
$store = Mage::app()->getStore();
}
parent::loadData($product, $store);
$this->setTag1($this->expodeTags($this->getTag1()));
$this->setTag2($this->expodeTags($this->getTag2()));
$this->setTag3($this->expodeTags($this->getTag3()));
return true;
}
/**
* @param array $tagsArray
* @return array
*/
private function expodeTags(array $tagsArray)
{
$finalTags = array();
foreach ($tagsArray as $tag) {
$property = explode(':', $tag);
$values = explode(',', $property[1]);
foreach ($values as $value) {
$finalTags[] = $property[0].':'.$value;
}
}
return $finalTags;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment