Oke, setelah beberapa saat saya menemukan solusi kalau-kalau orang lain membutuhkannya .. Magento menggunakan pendekatan lain untuk instantiate objek, cara tradisional untuk instantiate objek di Magento 1.x menggunakan "Mage :: getModel (..)", ini telah berubah di Magento 2. Sekarang Magento menggunakan manajer objek untuk membuat instance objek, saya tidak akan memasukkan detail tentang cara kerjanya .. jadi, kode yang setara untuk membuat pelanggan di Magento 2 akan terlihat seperti ini:
<?php
namespace ModuleNamespace\Module_Name\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @var \Magento\Customer\Model\CustomerFactory
*/
protected $customerFactory;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Customer\Model\CustomerFactory $customerFactory
) {
$this->storeManager = $storeManager;
$this->customerFactory = $customerFactory;
parent::__construct($context);
}
public function execute()
{
// Get Website ID
$websiteId = $this->storeManager->getWebsite()->getWebsiteId();
// Instantiate object (this is the most important part)
$customer = $this->customerFactory->create();
$customer->setWebsiteId($websiteId);
// Preparing data for new customer
$customer->setEmail("email@domain.com");
$customer->setFirstname("First Name");
$customer->setLastname("Last name");
$customer->setPassword("password");
// Save data
$customer->save();
$customer->sendNewAccountEmail();
}
}
Semoga cuplikan kode ini membantu orang lain ..