/ / Magento2: Wie füge ich mehrere Produkte in den Einkaufswagen ein? - Magento2

Magento2: Wie füge ich mehrere Produkte im Warenkorb hinzu, indem ich ein einzelnes Formular einreiche? - Magento2

Ich bin neu in Magento2 und benutze Version 2.1. Ich muss mehrere Produkte im Warenkorb hinzufügen, das Produkt kann jeden Typ haben und ich möchte auch die Ajax-Validierung mit dieser Funktionalität hinzufügen.

Kann jemand eine Idee haben, dies zu erreichen?

Vielen Dank, Chandan

Antworten:

0 für die Antwort № 1

Hallo Ich habe Lösung für das Hinzufügen mehrerer Produkte im Warenkorb in For-Schleife: Bitte beachten Sie den folgenden Code, um diese Funktionalität in MAGENTO 2 zu implementieren

   if ($product_id) {
$storeId = $objectManager->get("MagentoStoreModelStoreManagerInterface")->getStore()->getId();
try {


if(isset($params["super_attribute"][$product_id])){
$params_post = array();
$params_post["form_key"] = $this->formKey->getFormKey();
$params_post["qty"] = 1;
$params_post["super_attribute"] =  $params["super_attribute"][$product_id];
$finalproduct = $this->productRepository->getById($product_id, false, $storeId);
$this->cart->addProduct($finalproduct, $params_post);
} else {
$params_post = array();
$params_post["form_key"] = $this->formKey->getFormKey();
$params_post["qty"] = 1;

$finalproduct = $this->productRepository->getById($product_id, false, $storeId);
$this->cart->addProduct($finalproduct, $params_post);
}

} catch (NoSuchEntityException $e) {

}
}