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 № 1Hallo 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) {
}
}