Skip to content

Instantly share code, notes, and snippets.

@Rafawastaken
Last active April 15, 2025 23:21
Show Gist options
  • Save Rafawastaken/212af15515049c6d7cd01b217eb10e58 to your computer and use it in GitHub Desktop.
Save Rafawastaken/212af15515049c6d7cd01b217eb10e58 to your computer and use it in GitHub Desktop.
smartmarketingps mapProduct
public static function mapProduct($product, $lang, $currency)
{
if (is_array($product)) {
$product = new Product($product['id_product'], true, $lang);
} else {
$product = new Product($product->id, true, $lang);
}
$link = new Link();
// $desc = empty($product->description_short) ? filter_var(substr($product->description, 0, 800), FILTER_SANITIZE_STRING) : filter_var($product->description_short, FILTER_SANITIZE_STRING);
$desc = "";
$price = $product->getPrice(true);
$salePrice = $product->getPrice(true);
if ($price == $salePrice) {
$salePrice = 0;
}
$url = $link->getProductLink($product, null, null, null, $lang, null);
if (strpos($url, '?') !== false) {
$concatChar = '&';
} else {
$concatChar = '?';
}
$url = $link->getProductLink($product, null, null, null, $lang, null) . $concatChar . 'SubmitCurrency=1&id_currency=' . $currency;
$img = $product->getCover($product->id);
$ssl = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
$imageUrl = $ssl . $link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], 'home_default');
// $categories = static::buildBreadcrumbs($product->getCategories(), $lang);
$categories = array();
$relatedProducts = array();
// $acessories = Product::getAccessoriesLight($lang, $product->id);
// foreach ($acessories as $item) {
// $relatedProducts[] = $item['id_product'];
// }
return array(
'product_identifier' => $product->id,
'name' => $product->name,
'description' => $desc,
'sku' => $product->reference,
'upc' => "",
'ean' => $product->ean13,
'link' => $url,
'image_link' => $imageUrl,
'price' => $price,
'sale_price' => $salePrice,
'brand' => "",
'categories' => "",
'related_products' => ""
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment