OpenCart 🇺🇦

Метод ControllerOpenbayAmazonProduct::fillDefaultValues(...)

Схема

private mixed fillDefaultValues ( $product_id, $fields_array, $var = '' )

Аргументы

Аргумент Возможный тип Описание
$product_id
$fields_array
$var = ''

Описание

Метод пока еще не документирован.

Исходный код

$this->load->model('catalog/product');
$this->load->model('setting/setting');
$this->load->model('openbay/amazon');

$openbay_settings = $this->model_setting_setting->getSetting('openbay_amazon');

$product_info = $this->model_catalog_product->getProduct($product_id);
$product_info['description'] = trim(utf8_encode(strip_tags(html_entity_decode($product_info['description']), "<br>")));
$product_info['image'] = HTTPS_CATALOG . 'image/' . $product_info['image'];

$tax_added = isset($openbay_settings['openbay_amazon_listing_tax_added']) ? $openbay_settings['openbay_amazon_listing_tax_added'] : 0;
$default_condition =  isset($openbay_settings['openbay_amazon_listing_default_condition']) ? $openbay_settings['openbay_amazon_listing_default_condition'] : '';
$product_info['price'] = number_format($product_info['price'] + $tax_added / 100 * $product_info['price'], 2, '.', '');

/*Key must be lowecase */
$defaults = array(
	'sku' => $product_info['sku'],
	'title' => $product_info['name'],
	'quantity' => $product_info['quantity'],
	'standardprice' => $product_info['price'],
	'description' => $product_info['description'],
	'mainimage' => $product_info['image'],
	'currency' => $this->config->get('config_currency'),
	'shippingweight' => number_format($product_info['weight'], 2, '.', ''),
	'conditiontype' => $default_condition,
);

$this->load->model('localisation/weight_class');
$weightClass = $this->model_localisation_weight_class->getWeightClass($product_info['weight_class_id']);
if(!empty($weightClass)) {
	$defaults['shippingweightunitofmeasure'] = $weightClass['unit'];
}

$this->load->model('catalog/manufacturer');
$manufacturer = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
if(!empty($manufacturer)) {
	$defaults['manufacturer'] = $manufacturer['name'];
	$defaults['brand'] = $manufacturer['name'];
}

$productImages = $this->model_catalog_product->getProductImages($product_id);
$imageIndex = 1;
foreach($productImages as $productImage) {
	$defaults['pt' . $imageIndex] = HTTPS_CATALOG . 'image/' . $productImage['image'];
	$imageIndex ++;
}

if(!empty($product_info['upc'])) {
	$defaults['type'] = 'UPC';
	$defaults['value'] = $product_info['upc'];
} else if(!empty($product_info['ean'])) {
	$defaults['type'] = 'EAN';
	$defaults['value'] = $product_info['ean'];
}

$meta_keywords = explode(',', $product_info['meta_keyword']);
foreach ($meta_keywords as $index => $meta_keyword) {
	$defaults['searchterms' . $index] = trim($meta_keyword);
}

$this->load->library('amazon');
if($var !== '' && $this->openbay->addonLoad('openstock')) {
	$this->load->model('tool/image');
	$this->load->model('openstock/openstock');
	$optionStocks = $this->model_openstock_openstock->getProductOptionStocks($product_id);

	$option = null;
	foreach ($optionStocks as $optionIterator) {
		if($optionIterator['var'] === $var) {
			$option = $optionIterator;
			break;
		}
	}

	if($option != null) {
		$defaults['sku'] = $option['sku'];
		$defaults['quantity'] = $option['stock'];
		$defaults['standardprice'] = number_format($option['price'] + $tax_added / 100 * $option['price'], 2, '.', '');
		$defaults['shippingweight'] = number_format($option['weight'], 2, '.', '');

		if(!empty($option['image'])) {
			$defaults['mainimage'] = HTTPS_CATALOG . 'image/' . $option['image'];
		}
	}
}

if($defaults['shippingweight'] <= 0) {
	unset($defaults['shippingweight']);
	unset($defaults['shippingweightunitofmeasure']);
}

$filledArray = array();

foreach($fields_array as $field) {

	$value_array = array('value' => '');

	if(isset($defaults[strtolower($field['name'])])) {
		$value_array = array('value' => $defaults[strtolower($field['name'])]);
	}

	$filledItem = array_merge($field, $value_array);

	$filledArray[] = $filledItem;
}
return $filledArray;