Jump to content

Edit History

BenDev

BenDev


Add the modified code (display cart not working yet)

Hello,

This file receive a request by an extern app, and it is located at the prestashop basepath along with the index.php...

 

<?php
require_once('config/config.inc.php');
include_once('classes/Cookie.php');
require_once('vendor/autoload.php');

ini_set("display_errors", 1);

$debug = fopen("debug.txt", "a");
$context = Context::getContext();


$basketHeader = "Location: https://www.my-site.com/fr/panier";

$products_type_max = 5;
$basket = array();

/**
 * Get the infos or redirect
 */
if(!empty($_GET)){
	foreach($_GET as $key=>$value){
		$basket[$key]=preg_replace("/[^0-9]/", "", $value);
		//fwrite($debug, $key. ' = '.$basket[$key]);
	}
	
	if(count($basket) != (2 * $products_type_max) ){
		header($basketHeader);
		exit();
	}
}
else{
	header($basketHeader);
	exit();
}

fwrite($debug, json_encode($context));

/**
 * Try to set basket
 */
if (isset($basket))
{
	if (is_null($context->cart)) {
    $context->cart = new Cart($context->cookie->id_cart);
		$context->cart->id_shop_group = 1;
		$context->cart->id_shop = 1;
		if(!isset($cookie->id_customer)){
			$context->cart->id_customer = 0;
			$context->cart->id_address_delivery = 0;
		} else {
			$context->cart->id_customer = (int)($cookie->id_customer);
			$context->cart->id_address_delivery = (int)(Address::getFirstCustomerAddressId($context->cart->id_customer));
		}
		$context->cart->id_guest=(int)($cookie->id_guest);
		$context->cart->id_address_invoice = $context->cart->id_address_delivery;
		$context->cart->id_lang = (int)($cookie->id_lang);
		$context->cart->id_currency = 1;
		$context->cart->id_carrier = 0;
		$context->cart->recyclable = 0;
		$context->cart->gift = 0;
		$context->cart->add();
		$cookie->id_cart = (int)($context->cart->id);    
		$context->cart->update();
	}
	
	for($i=0;$i<$products_type_max;$i++){
		if($basket['qty'.$i]>0){
			$context->cart->updateQty($basket['qty'.$i],$basket['id'.$i]);
		}
	}

	if(!($context->cart->containsProduct(13))){
		$context->cart->updateQty(1,13);
	}

	fwrite($debug, "Cart = ");
	fwrite($debug, json_encode($context->cart));

	fclose($debug);
	
	header($basketHeader);
	exit();
}

 

BenDev

BenDev

Hello,

This file receive a request by an extern app, and it is located at the prestashop basepath along with the index.php...

×
×
  • Create New...