2017-01-18 13 views
0

Ниже мой код наблюдатель:Как я могу сохранить пользовательские значения поля в таблице customer_entity в Magento 2 с помощью наблюдателя

 
<?php 

class CustomerOrderCountObserver implements ObserverInterface 
{ 

    /** 
    * @var customerFactory 
    */ 
    private $customerFactory; 

    /** 
    * 
    * @param CustomerFactory $customerFactory 
    */ 
    public function __construct(
     CustomerFactory $customerFactory 
    ) { 
      $this->customerFactory = $customerFactory; 
    } 

    /** 
    * Upgrade customer password hash when customer has logged in 
    * 
    * @param \Magento\Framework\Event\Observer $observer 
    * @return void 
    */ 
    public function execute(\Magento\Framework\Event\Observer $observer) 
    { 
     $orderInstance = $observer->getEvent()->getdata(); 
     $orderIds = $observer->getEvent()->getdata('order_ids'); 
     $orderCount = is_array($orderIds)?count($orderIds):0; 
     $orderId = current($orderIds); 
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
     $session = $objectManager->get('Magento\Customer\Model\Session'); 

     if($session->isLoggedIn()) { 
      $customer = $this->customerFactory->create()->load($session->getCustomerId()); 
      $orderCount = $orderCount + $customer->getOrderCount(); 
      $customer->setOrderCount($orderCount); 
      $customer->save($customer); 
     } 
    } 
} 

Я не знаю, что я делаю неправильно с этим. Это не сохраняет значение столбца клиента order_count

ответ

0

Try загрузки клиента от модели

$customer = Mage::getModel('customer/customer')->load($session->getCustomerId()); 
+0

я хочу, чтобы получить решение о Magento 2! кстати спасибо –

 Смежные вопросы

  • Нет связанных вопросов^_^