2017-08-08 5 views
0

私はmartyshka/ShoppingCartコンポーネントを実装しようとしています。私が見つけたのは、アイテムを追加している間にハイドレーターがヌルだったのですが、強制したときには(コンポーネントに設定すると)機能しませんでした。martyshka/ShoppingCart ZF2コンポーネントが動作しないのはなぜですか(ハイドレーターの問題かもしれません)?

Here's my controller

<?php 
namespace Publico\Controller; 

use Doctrine\ORM\EntityManager; 
use ShoppingCart\Controller\Plugin\ShoppingCart; 
use Zend\Mvc\Controller\AbstractActionController; 
use Zend\View\Model\ViewModel; 

class CarrinhoController extends AbstractActionController 
{ 
    private $carrinho; 
    private $entityManager; 

    protected function setCarrinho(ShoppingCart $cart) 
    { 
     $this->carrinho = $cart; 
     return $this; 
    } 

    protected function getCarrinho() 
    { 
     if (null === $this->carrinho) { 
      $this->setCarrinho(new ShoppingCart()); 
     } 
     return $this->carrinho; 
    } 

    /*...*/ 

    public function indexAction() 
    { 
     try { 
      $carrinho = $this->getCarrinho(); 
     } catch (\Exception $e) { 
      die($e->getMessage()); 
     } 

     $carrinhoItems = [ 
      'carrinho' => $carrinho->cart(), 
      'valorTotal' => $carrinho->total_sum(), 
      'qtdTotal' => $carrinho->total_items(), 
     ]; 

     die($carrinhoItems); 

     return new ViewModel([ 
      'carrinho' => $this->carrinho->cart(), 
      'valorTotal' => $this->carrinho->total_sum(), 
      'qtdTotal' => $this->carrinho->total_items(), 
     ]); 
    } 
    /*...*/ 
} 

Here's the component repo

答えて

1

このコンポーネントが使用するプラグイン "ShoppingCartの" を提供し、あなたがするShoppingCartのオブジェクトを作成する必要はありません。

あなたが適切モジュールとして、このコンポーネントをインストールする場合は、

はちょうど私がやったことだが、私は彼の「父」ZendCartがインストールされていることを、あなたのアクション(Action)に

$this->ShoppingCart() 
+0

をそれを使用しています。 ありがとうございます。 –

+0

@SalustianoMuniz偉大な、知っておいて、私はまた、同じ問題がいくつかの時間前に立ち往生していた。 –

関連する問題