문제

Warehouses라는 모델과 관련된 창고 제품이라는 모델이 있습니다.내가웨어 하우스 제품은 문제를 일으키지 않는 TRY-CATCH에 싸여있는 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