tgonzalez Posted January 9, 2020 Share Posted January 9, 2020 (edited) Hola estoy intentando crear precios específicos, parece que los comandos lo hago bien, pero cuando añado productos al carro más de 10, le aparecen a los clientes como de 0€ ¿qué estoy haciendo mal? <?php $precio=5000; //precio sin comas $precioOri=65.00;//precio original $from = date("Y") . "-" . date("m") . "-" . date("d") . " 00:00:00"; $DatetimeFechaActual = new DateTime("NOW"); $DatetimeFechaActual->add(new DateInterval('P2D')); $to=$DatetimeFechaActual->format("Y-m-d")." 00:00:00"; //echo $from."<br>".$to; $precioFloat=floatval(floatval($precio)/100); $specificPrice = new SpecificPrice(); $specificPrice->id_product = $id; // $specificPrice->id_product_attribute = (int)$id_product_attribute; $specificPrice->id_shop = 0; //$specificPrice->id_shop_group = $this->context->shop->id_shop_group; $specificPrice->id_currency = 0; $specificPrice->id_country = Tools::getValue('sp_id_country'); $specificPrice->id_group = 0; $specificPrice->id_customer = 0; $specificPrice->price = $precioFloat; $r=($precioFloat/$precioOri*100); $r=abs(abs($r)-100); $specificPrice->reduction=(float)$precioFloat; $specificPrice->reduction_type="amount"; $specificPrice->reduction_tax = 0; //$specificPrice->price=$precio; $specificPrice->from_quantity =(int) $cantidad; $specificPrice->from = $from; $specificPrice->to = $to; $specificPrice->add(); $addedPriceId = $specificPrice->id; ?> Creo que lo he hecho bien, alguien me puede echar un cable Edited January 9, 2020 by tgonzalez (see edit history) Link to comment Share on other sites More sharing options...
ricardopxl Posted February 17, 2020 Share Posted February 17, 2020 (edited) 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; } Edited February 17, 2020 by ricardopxl (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now