0

送料を追加するために、CI のネイティブ カート クラスの機能を拡張しようとしています。MY_Cart.php ファイルを application/core に追加することから始めました。現時点ではこれを行うだけです:

class MY_Cart extends CI_Cart {

$CI =& get_instance();

public function __construct() {
    parent::__construct();
}


public function add_shipping() {
       echo 'this function will eventually add shipping';       
}
}

そして、カートにアイテムを追加するメソッドで、新しい add_shipping メソッドを呼び出そうとしました。

public function add() {
    $data['product'] = $this->Model_products->get_product_by_id($_POST['product_id']);
            $data = array(
           'id'      => $_POST['product_id'],
           'qty'     => 1,
           'price'   => $data['product'][0]->price ,
           'name'    => $data['product'][0]->product_name

        );

       $this->cart->add_shipping();
       $this->cart->insert($data);

         $data['title'] = 'Basket';

      $this->load->view('wrapper-no-cart','basket',$data);
}

しかし、一般的なサーバーエラーが発生します。私が間違っていることはありますか?コア ライブラリを拡張すると、作成した新しいメソッドを呼び出せるようになると思いましたか?

4

3 に答える 3

1

このようなことを試してください。 TOTAL に送料のみを追加する

if (!defined('BASEPATH'))
   exit('No direct script access allowed');

class MY_Cart extends CI_Cart
{
    public function __construct ( $params = array() )
    {
        parent::__construct ( $params ) ;
    }

    public function shipping($cost='0.3')
    {
        if( !$this->cart->total_items() > 1) return;

        $this->cart->total() =+  ( $this->cart->total() + (float)$cost );
        return $this;
    }

    public function __get ( $name )
    {
        $instance =&get_instance();
        return $instance->{$name};
    }
}
于 2013-04-29T12:11:47.067 に答える