我有一个名为仓库的型号,另一个被称为仓库产品相关的仓库。我拥有的问题是仓库产品不节省,尽管它是在一个尝试捕获中包装的生成鸟类函数,它不会产生任何问题。

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检查是真的。它节省了,但由于发生了世代古代替代代码,它没有特别保存。

对于添加方法,我将此检查完全删除加载语句,然后我在设置数据之前简单地运行此生成码次码。

所有工作伟大!

许可以下: CC-BY-SA归因
scroll top