Skip to content

Instantly share code, notes, and snippets.

@JasonMortonNZ
Created November 30, 2015 19:34
Show Gist options
  • Save JasonMortonNZ/90ada76ad5511a37d2c6 to your computer and use it in GitHub Desktop.
Save JasonMortonNZ/90ada76ad5511a37d2c6 to your computer and use it in GitHub Desktop.
Magento 2 module to extend Customer (not working)
<?php
namespace Jason\OCUser\Model;
use Magento\Customer\Model\Customer as MCustomer;
class Customer extends MCustomer
{
/**
* Load customer by email
*
* @param string $customerEmail
* @return $this
*/
public function loadByEmail($customerEmail)
{
die('Not reaching this :( ');
}
}
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Customer\Api\Data\CustomerInterface" type="Jason\OCUser\Model\Customer" />
<type name="Magento\Framework\Model\ActionValidator\RemoveAction">
<arguments>
<argument name="protectedModels" xsi:type="array">
<item name="customer" xsi:type="string">Jason\OCUser\Model\Customer</item>
</argument>
</arguments>
</type>
</config>
<?php
namespace Jason\OCUser\Setup;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\InstallSchemaInterface;
class InstallSchema implements InstallSchemaInterface
{
/**
* Installs DB schema for a module
*
* @param SchemaSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
/**
* Add salt column and oc user status
*/
$installer->getConnection()->addColumn(
'customer_entity',
'oc_salt',
[
'type' => Table::TYPE_TEXT,
'nullable' => true,
'default' => null,
'length' => 9,
'comment' => ''
]
);
$installer->getConnection()->addColumn(
'customer_entity',
'oc_user',
[
'type' => Table::TYPE_BOOLEAN,
'nullable' => false,
'default' => 0,
'comment' => ''
]
);
$installer->endSetup();
}
}
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Jason_OCUser" setup_version="2.0.0"/>
<sequence>
<module name="Magento_Customer"/>
</sequence>
</config>
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Jason_OCUser',
__DIR__
);
<?php
namespace Jason\OCUser\Setup;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\UpgradeSchemaInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
/**
* Installs DB schema for a module
*
* @param SchemaSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
/**
* Add salt column and oc user status
*/
$installer->getConnection()->addColumn(
'customer_entity',
'oc_salt',
[
'type' => Table::TYPE_TEXT,
'nullable' => true,
'default' => null,
'length' => 9,
'comment' => ''
]
);
$installer->getConnection()->addColumn(
'customer_entity',
'oc_user',
[
'type' => Table::TYPE_BOOLEAN,
'nullable' => false,
'default' => 0,
'comment' => ''
]
);
$installer->endSetup();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment