質問

私は倉庫と呼ばれるモデルと、それが関連する倉庫製品と呼ばれるものと呼ばれます。私が持っている問題は、save()関数が問題を生じていないテストキャッチに包まれているにもかかわらず、倉庫製品が保存されないということです。

try {
    $model->save();
    $session->addSuccess($this->__('The product has been saved.'));
    $this->_redirect('*/*/');

    return;            
} catch (Mage_Core_Exception $e) {
    $session->addError($e->getMessage());
} catch (Exception $e) {
    $session->addError($this->__('An error occurred while saving this product.'));
}
.

モデルを使用してテーブルを返す場合は、次の手順を受けます。

$model->getResource()->getTable();
// Can't retrieve entity config
.

これは明らかに私のセットアップで何かがあるものがあることを示唆している -

<inventorymanagement>
    <class>CompanyName_InventoryManagement_Model</class>
    <resourceModel>inventorymanagement_resource</resourceModel>
</inventorymanagement>
<inventorymanagement_resource>
    <class>TheGenieLab_InventoryManagement_Model_Resource</class>
    <entities>
        <warehouse>
            <table>inventorymanagement_warehouse</table>
        </warehouse>
        <warehouse_product>
            <table>inventorymanagement_warehouse_product</table>
        </warehouse_product>
    </entities>
</inventorymanagement_resource>
.

リソースセクション:

<resources>
    <inventorymanagement_setup>
        <setup>
            <module>TheGenieLab_InventoryManagement</module>
        </setup>
    </inventorymanagement_setup>
</resources>
.

私のファイルは以下のようにレイアウトされています。

- Resource
    - Warehouse
        - Product
            - Collection.php
        - Collection.php
        - Product.php
    - Warehouse.php
- Warehouse
    - Product.php
- Warehouse.php
.

私がする必要がある他のものはありますか?

編集

これはいくつかの追加のコードです 倉庫> Product.Php

class CompanyName_InventoryManagement_Model_Warehouse_Product extends Mage_Core_Model_Abstract
{
    protected function _construct()
    {
        $this->_init('inventorymanagement/warehouse_product');
    }
}
.

リソース>倉庫> Product.Php

class CompanyName_InventoryManagement_Model_Resource_Warehouse_Product extends Mage_Core_Model_Mysql4_Abstract
{
    protected function _construct()
    {
        $this->_init('inventorymanagement/warehouse_product', 'id');
    }
}
.

リソース>ウェアハウス>製品> collection.php

class CompanyName_InventoryManagement_Model_Resource_Warehouse_Product_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    protected function _construct()
    {
        $this->_init('inventorymanagement/warehouse_product');
    }
}
.

役に立ちましたか?

解決

私はそれを考え出した。

$model->save();がこれを持っていました:

$model = Mage::getModel('inventorymanagement/warehouse_product');
$product = $postData['warehouse_product'];
if (isset($product['id'])) {
    $model->load($product['id']);
}
$product['product_id'] = str_replace('product/', '', $product['product_id']);
unset($product['save']);
$model->setData($product);
.

問題は、$ Product ['ID']がフォーム上の隠しフィールドとして設定されているため、常に設定されました。したがって、ISSETチェックは真でした。それは節約されていましたが、$model->load()が起こっていたため、特に節約されていませんでした。

追加方法では、この小切手をLOADステートメントと一緒に完全に削除してから、データを設定する前にこのunset($product['id']);を実行しました。

すべての作業!

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top