我正在尝试创建客户和产品之间的关系表。我们的计划是,在编辑客户时,我将拥有一个单独的选项卡,以便在编辑产品时以“相关产品”选项卡的方式将产品分配给该客户。Magento 1.9.2创建客户和产品之间的关系
到目前为止,我能够向管理员添加一个选项卡,但大步骤在我面前。我想创建一个多一对多的关系表,所以我添加了一个文件mysql4安装-0.1.0.php与下面:
$installer = $this;
$installer->startSetup();
/**
* Create table 'customerproduct/product_relation'
*/
$table = $installer->getConnection()
->newTable($installer->getTable('customerproduct/product_relation'))
->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
'nullable' => false,
'primary' => true,
), 'Customer ID')
->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'unsigned' => true,
'nullable' => false,
'primary' => true,
), 'Product ID')
->addIndex($installer->getIdxName('customerproduct/product_relation', array('product_id')),
array('product_id'))
->addForeignKey($installer->getFkName('customerproduct/product_relation', 'product_id', 'customer/product', 'entity_id'),
'product_id', $installer->getTable('catalog/product'), 'entity_id',
Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->addForeignKey($installer->getFkName('customerproduct/product_relation', 'customer_id', 'customer/entity', 'entity_id'),
'customer_id', $installer->getTable('customer/entity'), 'entity_id',
Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->setComment('Customer Product Relation Table');
$installer->getConnection()->createTable($table);
$installer->endSetup();
$installer->installEntities();
不知道上面是在正确的它甚至没有得到这个文件。我将不胜感激关于如何解决这个问题的一些指导,以及我如何控制挽救关系。我在网上查找了类似的解决方案,但没有运气。
编辑1:
config.xml文件看起来像下面:
<config>
<modules>
<Trike_Customerproduct>
<version>0.1.0</version>
</Trike_Customerproduct>
</modules>
<adminhtml>
<layout>
<updates>
<customerproduct>
<file>trike_customerproduct.xml</file>
</customerproduct>
</updates>
</layout>
</adminhtml>
<global>
<blocks>
<customerproduct>
<class>Trike_Customerproduct_Block</class>
</customerproduct>
</blocks>
</global>
</config>
我注意到,它并没有出现在core_resource表。配置版本设置为0.1.0,安装程序名为mysql4-install-0.1.0.php,并将其放置在以下文件夹中:sql> customerproduct_setup
第一个要解决的问题是,为什么没有被访问的安装文件。它在模块的config.xml中如何链接? – Reflexorozy
尝试从core_resources表中删除此模块的相应行。在创建安装文件之前,您的模块可能已经注册了0.1.0版本。如果它不起作用,请粘贴此模块的config.xml。 –