4


カスタムのロイヤルティ ポイント モジュールに取り組んでいます。チェックアウト中に、顧客は自分のポイントを引き換えるオプションがあります。
モジュールのセットアップで、redee_points eav_attribute を作成し (eav_attribute テーブルに存在します)、その属性を見積もりに追加し
ました。

  • mysql4-install-0.1.0.php で$installer->installEntities();を呼び出します。
  • Namespace_Module_Model_Resource_Eav_Mysql4_Setup (これは Mage_Eav_Model_Entity_Setup を拡張します) には、以下を含む配列のみを返すメソッドpublic function getDefaultEntities()が 1 つだけあります。

       'quote' => array(
            'entity_model'  => 'sales/quote',
            'table'         => 'sales/quote',
            'attributes'    => array(
                'redeemed_points'   => array('type' => 'static')
            ),
        ),
    
  • 再び mysql4-install-0.1.0.php で、このように sales_flat_quote テーブルに列を作成します

       //add redeemed_points to quote table
       $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'redeemed_points', 'bigint(20)');
       $installer->addAttribute('quote', 'redeemed_points', array('type'=>'static'));
    

チェックアウトでポイントを交換すると、Mage_Checkout_Model_Type_Onepage を拡張するクラスのメソッド savePoints($data) が呼び出されます。

public function savePoints($data)
{
    //save data
    if ($data == 1) {
        $redeemedPoints = Mage::helper('points')->getRedeemablePoints();
        $this->getQuote()->setRedeemedPoints($redeemedPoints['points']);
    } else {
        $this->getQuote()->setRedeemedPoints(0);
    }
    $this->getQuote()->collectTotals()->save();

    $this->getCheckout()
         ->setStepData('points', 'complete', true);
    if ($this->getQuote()->isVirtual()) {
        $this->getCheckout()->setStepData('payment', 'allow', true);
    } else {
        $this->getCheckout()->setStepData('shipping_method', 'allow', true);
    }

    Mage::helper('firephp')->debug($this->getQuote()->debug());

    return array();
}

firephp で見積もりオブジェクトをデバッグしていることに気付くでしょう。この時点で (チェックアウトのこのステップで、見積もりに保存した直後です)、redeed_points 属性が正しい値で表示されます。
私の問題は、次のステップでこの属性が見積もりオブジェクトから削除されていることです:(
したがって、recomeded_points属性を見積もりオブジェクトに含めることができていないことは理解していますが、何が欠けているのか本当にわかりません。 ..
何か思い当たることはありますか?

4

3 に答える 3

7

var/cache/* を手動で削除してみてください。DB スキーマはそこにキャッシュされ、Magento は新しいテーブル列がそこにある場合でも取得しないことがあります。また、これはバックエンドでキャッシュのクリア機能を使用してもクリアされないようですが、ディレクトリ内のすべてを手動で削除することによってのみクリアされます。

于 2012-07-17T23:48:20.940 に答える
1

次の拡張例には、プログラムによるキャッシュ クリアが含まれています。

$installer = Mage::getResourceModel('sales/setup', 'sales_setup');

    $installer->startSetup();

    $installer->addAttribute('order', 'new_attribute', array('type'=>'boolean','default'=>0));
    $installer->addAttribute('quote', 'new_attribute', array('type'=>'boolean','default'=>0));


    // Refresh DB table describing cache programmatically

    if (method_exists($this->_conn, 'resetDdlCache')) {
        $this->_conn->resetDdlCache('sales_flat_order');
        $this->_conn->resetDdlCache('sales_flat_quote');
    }

$installer->endSetup();
于 2016-12-13T16:46:27.140 に答える
0

最も簡単な方法があります。次の例を試してください。

$installer = Mage::getResourceModel('sales/setup', 'sales_setup');
    $installer->startSetup();
    $installer->addAttribute('order', 'new_attribute', array('type'=>'boolean','default'=>0));
    $installer->addAttribute('quote', 'new_attribute', array('type'=>'boolean','default'=>0));
$installer->endSetup();
于 2016-02-17T23:43:02.830 に答える