51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* TNT OFFICIAL MODULE FOR PRESTASHOP.
|
|
*
|
|
* @author GFI Informatique <www.gfi.fr>
|
|
* @copyright 2016-2017 GFI Informatique, 2016-2017 TNT
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
|
*/
|
|
|
|
require_once _PS_MODULE_DIR_.'tntofficiel/libraries/TNTOfficiel_Debug.php';
|
|
require_once _PS_MODULE_DIR_.'tntofficiel/libraries/TNTOfficiel_DbUtils.php';
|
|
|
|
class TNTOfficiel_Product
|
|
{
|
|
/**
|
|
* Get the configured attributes for a product.
|
|
*
|
|
* @param int $productId
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getProductAttributes($productId)
|
|
{
|
|
TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__));
|
|
|
|
//configured attributes
|
|
$tntCarrierAssociations = Configuration::get('TNT_CARRIER_ASSOCIATIONS');
|
|
$attributesNames = array();
|
|
if (!empty($tntCarrierAssociations)) {
|
|
$attributesNames = explode(',', $tntCarrierAssociations);
|
|
}
|
|
|
|
//columns from the product table
|
|
$productColumns = TNTOfficiel_DbUtils::getColumnsFromTable('product');
|
|
$attributes = array();
|
|
$attribute = array();
|
|
//product
|
|
$product = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'product WHERE id_product = '.(int)$productId);
|
|
|
|
foreach ($attributesNames as $attributeName) {
|
|
if (in_array($attributeName, $productColumns)) {
|
|
$attribute['code'] = $attributeName;
|
|
$attribute['value'] = $product[$attributeName];
|
|
$attributes[] = $attribute;
|
|
}
|
|
}
|
|
|
|
return $attributes;
|
|
}
|
|
}
|