php
  • magento2
  • 2016-09-28 52 views 1 likes 
    1

    我需要刪除簡單產品從購物車。僅適用於配置產品如何刪除magento中的簡單產品車2.1

    <a href="#" 
        title="<?php echo $block->escapeHtml(__('Remove item')); ?>" 
        class="action action-delete btn-remove btn-remove2 remove-btn" 
        data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'> 
        <i class="fa fa-times-circle" aria-hidden="true"></i> 
        <?php /* <span> 
         <?php /* @escapeNotVerified */echo __('Remove item')?> 
        </span> */ ?> 
    </a> 
    

    上面的代碼工作配置產品

    1. 如何從車中移除簡單的產品

      刪除項目的選擇嗎?

    +0

    將這項工作? https://magento.stackexchange.com/questions/141314/remove-items-from-cart-in-controller-magento2 – Joey

    回答

    0

    要刪除購物車,你需要遵循這些功能項:

    public function deleteQuoteItems(){ 
        $checkoutSession = $this->getCheckoutSession(); 
        $allItems = $checkoutSession->getQuote()->getAllVisibleItems();//returns all teh items in session 
        foreach ($allItems as $item) { 
        $itemId = $item->getItemId();//item id of particular item 
        $quoteItem=$this->getItemModel()->load($itemId);//load particular item which you want to delete by his item id 
        $quoteItem->delete();//deletes the item 
        } 
        } 
        public function getCheckoutSession(){ 
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();//instance of object manager 
        $checkoutSession = $objectManager->get('Magento\Checkout\Model\Session');//checkout session 
        return $checkoutSession; 
        } 
    
        public function getItemModel(){ 
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();//instance of object manager 
        $itemModel = $objectManager->create('Magento\Quote\Model\Quote\Item');//Quote item model to load quote item 
        return $itemModel; 
        } 
    
    相關問題