Jump to content

Edit History

ricardopxl

ricardopxl

El problema es cómo estás trabajando las fechas. Te adjunto a continuación un script que he creado que hace lo que tu necesitas:

<?php
/*
@Author: 	Ricardopxl
@URL: 		https://digitag.cl
@Date: 		17-02-2020
*/

	require('../config/config.inc.php');
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	set_time_limit(0);
	ini_set('memory_limit',-1);
	$_SERVER['REQUEST_METHOD'] = 'POST';
	$sl = "\n"; # FOR TERMINAL
	#$sl = "<br>"; # FOR BROWSER

	/*FUNCTION TO GET ID_PRODUCT BY ID_REFERENCE, NO WORK WITH IPA, ONLY SINGLE PRODUCT*/
	function getIdByReference($reference)
	{
		$sql = 'SELECT p.id_product FROM `'._DB_PREFIX_.'product` as p WHERE p.reference = "'.$reference.'";';
		if ($results = Db::getInstance()->ExecuteS($sql)){
			if (count($results) == 1 AND !empty($results)) {
				return $results[0]['id_product'];
			}else{
				return false;
			}
		}
	}

	# DATES
	$from = date('Y-m-d H:i:s');
	$to = date('Y-m-d 23:59:59', strtotime($from. ' + 2 days')); # INCREASE 2 DAYS
	
	foreach (arreglo() as $reference => $a) {
		$id_product = getIdByReference($reference);
		if ($id_product==false) {
			continue;
		}
		$specificPrice = new SpecificPrice();
		$specificPrice->id_product = getIdByReference($reference);
		$specificPrice->id_shop = 1; # SPECIFIC ID SHOP
		$specificPrice->id_currency = 0; # ALL CURRENCY
		$specificPrice->id_country = 0; # ALL COUNTRY
		$specificPrice->id_group = 0; # ALL CUSTOMER GROUP
		$specificPrice->id_customer = 0; # ALL CUSTOMERS
		$specificPrice->id_product_attribute = 0; # ALL PRODUCTS
		$specificPrice->reduction_type = ($a['type']=='$'?'amount':'percentage'); # IDENTIFY IF AMOUNT O PERCENTAGE
		$specificPrice->price = $a['price']; # NEW PRICE
		$specificPrice->from_quantity = 1; # QTY MINIMAL
		$specificPrice->reduction = number_format((float)str_replace(",", ".", $a['amount_discount']), 6, '.', ''); # REDUCTION;
		// # DATES
		$specificPrice->from = $from;
		$specificPrice->to = $to;

		try {
			$add = $specificPrice->add();
			if ($add) {
				print_r("AGREGADO ".$reference.$sl);
			}else{
				print_r("NO_AGREGADO_ ".$reference.$sl);
			}
		} catch (Exception $e) {
			echo "<pre>";
			print_r($e);
			print_r("NO_AGREGADO_CAT ".$reference.$sl);
			echo "</pre>";
		}

	
	}

	/*DATA PRODUCTS*/
	function arreglo(){
		$a['RCNC-24LGGS'] = array('price'=>'990','type'=>'$','amount_discount'=>'200'); # FOR SPECIFIC AMOUNT
		return $a;
	} 

 

ricardopxl

ricardopxl

El problema es cómo estás trabajando las fechas. Te adjunto a continuación un script que te será muy útil.

<?php
/*
@Author: 	Ricardopxl
@URL: 		https://digitag.cl
@Date: 		17-02-2020
*/

	require('../config/config.inc.php');
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	set_time_limit(0);
	ini_set('memory_limit',-1);
	$_SERVER['REQUEST_METHOD'] = 'POST';
	$sl = "\n"; # FOR TERMINAL
	#$sl = "<br>"; # FOR BROWSER

	/*FUNCTION TO GET ID_PRODUCT BY ID_REFERENCE, NO WORK WITH IPA, ONLY SINGLE PRODUCT*/
	function getIdByReference($reference)
	{
		$sql = 'SELECT p.id_product FROM `'._DB_PREFIX_.'product` as p WHERE p.reference = "'.$reference.'";';
		if ($results = Db::getInstance()->ExecuteS($sql)){
			if (count($results) == 1 AND !empty($results)) {
				return $results[0]['id_product'];
			}else{
				return false;
			}
		}
	}

	# DATES
	$from = date('Y-m-d H:i:s');
	$to = date('Y-m-d 23:59:59', strtotime($from. ' + 2 days')); # INCREASE 2 DAYS
	
	foreach (arreglo() as $reference => $a) {
		$id_product = getIdByReference($reference);
		if ($id_product==false) {
			continue;
		}
		$specificPrice = new SpecificPrice();
		$specificPrice->id_product = getIdByReference($reference);
		$specificPrice->id_shop = 1; # SPECIFIC ID SHOP
		$specificPrice->id_currency = 0; # ALL CURRENCY
		$specificPrice->id_country = 0; # ALL COUNTRY
		$specificPrice->id_group = 0; # ALL CUSTOMER GROUP
		$specificPrice->id_customer = 0; # ALL CUSTOMERS
		$specificPrice->id_product_attribute = 0; # ALL PRODUCTS
		$specificPrice->reduction_type = ($a['type']=='$'?'amount':'percentage'); # IDENTIFY IF AMOUNT O PERCENTAGE
		$specificPrice->price = $a['price']; # NEW PRICE
		$specificPrice->from_quantity = 1; # QTY MINIMAL
		$specificPrice->reduction = number_format((float)str_replace(",", ".", $a['amount_discount']), 6, '.', ''); # REDUCTION;
		// # DATES
		$specificPrice->from = $from;
		$specificPrice->to = $to;

		try {
			$add = $specificPrice->add();
			if ($add) {
				print_r("AGREGADO ".$reference.$sl);
			}else{
				print_r("NO_AGREGADO_ ".$reference.$sl);
			}
		} catch (Exception $e) {
			echo "<pre>";
			print_r($e);
			print_r("NO_AGREGADO_CAT ".$reference.$sl);
			echo "</pre>";
		}

	
	}

	/*DATA PRODUCTS*/
	function arreglo(){
		$a['RCNC-24LGGS'] = array('price'=>'990','type'=>'$','amount_discount'=>'200'); # FOR SPECIFIC AMOUNT
		return $a;
	} 

 

×
×
  • Create New...