Created
July 18, 2020 14:59
-
-
Save clipvui2512/ba26b89302868f2b0a6d944af034d35b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getJsondata($product){ | |
if(count($product['images']) == 0 ){ | |
return null; | |
} | |
$json = array( | |
'options' => array(), | |
'variants' => array(), | |
); | |
foreach ($product['options'] as $option){ | |
$json['options'][] = $option['name']; | |
} | |
foreach ($product['variants'] as $variant){ | |
$featured_image = $product['images'][0]['src']; | |
if(array_key_exists('featured_image',$variant)){ | |
if(is_array($variant['featured_image'] )){ | |
$featured_image = $variant['featured_image']['src']; | |
} | |
} | |
$sku_goc = $variant['sku'] ? $variant['sku'] : $product['id'].$product['created_at']; | |
if(strtolower($product['vendor']) == 'customcat'){ | |
$sku_goc = 'cc-'.$sku_goc ; | |
} | |
$json['variants'][] = array( | |
'options' => $this->getJsondataOption($json['options'],$variant), | |
'sku' => $sku_goc , | |
'price' => $variant['price'], | |
'img' => $featured_image, | |
); | |
} | |
return $json; | |
} | |
public function getJsondataOption($options,$variant){ | |
$rs = array(); | |
foreach ($options as $index=>$option){ | |
$option_index = $index + 1; | |
$rs[$index] = html_entity_decode($variant['option'.$option_index] , ENT_QUOTES ) ; | |
} | |
return $rs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment