Вы можете разместить этот код в файле PHP в вашем корневом каталоге и использовать простую форму, предписывающую этот страница с номером продукта & количество.
Просто изменение:
$idProduct= 19825 to $idProduct=$_POST["txtproductid"]
$qty=5 to $qty=$_POST["txtqty"];
$useSSL = true;
include('/config/config.inc.php');
include('/header.php');
global $params;
$errors = array();
$idProduct =19825;
$qty=5;
if ($cookie->isLogged())
{
/* Cart already exists */
if ((int)$cookie->id_cart)
{
$cart = new Cart((int)$cookie->id_cart);
}
if (!isset($cart) OR !$cart->id)
{
$cart = new Cart();
$cart->id_customer = (int)($cookie->id_customer);
$cart->id_address_delivery = (int) (Address::getFirstCustomerAddressId($cart->id_customer));
$cart->id_address_invoice = $cart->id_address_delivery;
$cart->id_lang = (int)($cookie->id_lang);
$cart->id_currency = (int)($cookie->id_currency);
$cart->id_carrier = 1;
$cart->recyclable = 0;
$cart->gift = 0;
$cart->add();
$cookie->id_cart = (int)($cart->id);
}
/* get product id and product attribure id */
$data = explode(",", $product);
$idProduct = $data[0]; */
$idProductAttribute = $data[1];
if ($qty != '')
{
$producToAdd = new Product((int)($idProduct), true, (int)($cookie->id_lang));
if ((!$producToAdd->id OR !$producToAdd->active) AND !$delete)
/* Product is no longer available, skip product */
continue;
/* Check the quantity availability */
if ($idProductAttribute > 0 AND is_numeric($idProductAttribute))
{
if (!$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
{
/* There is not enough product attribute in stock - set customer qty to current stock on hand */
$qty = getAttributeQty($idProductAttribute);
}
}
elseif (!$producToAdd->checkQty((int)$qty))
/* There is not enough product in stock - set customer qty to current stock on hand */
$qty = $producToAdd->getQuantity(idProduct);
$updateQuantity = $cart->updateQty((int)($qty), (int)($idProduct), (int)($idProductAttribute), NULL, 'up');
$cart->update();
}
/* redirect to cart
if (!sizeof($errors)) */
Tools::redirect('order.php');
}
else
{
Tools::redirect('/index.php');
}
$smarty->assign(array(
'id_customer' => (int)($cookie->id_customer),
'errors' => $errors
));
include_once('/footer.php');
Я не понимаю вашу точку зрения, продукт добавить programitacilly? если вы хотите добавить продукт, нажмите любую кнопку, которая. вы можете увидеть ajax-cart.js, который является блочным модулем js, с помощью которого вы можете добавить продукт. –
Нет, мне нужно знать класс или функцию сервера prestashop на стороне сервера для добавления отдельного продукта в корзину для платы за плату. Цель –