2017-04-15 6 views
0

カスタマーイメージ属性を作成して、顧客と管理者がアバターのようなプロフィールイメージをアップロード、更新、削除できるようにします。私はmagento 1ではこれがどのように可能であるか知っていますが、magento 2ではそうではありません。 。前もって感謝します。カスタマープロファイルイメージをmagentoにアップロードする方法2

+0

、registration.phpアプリの\コードを使用すると、解決策を得るHDID? – Jsparo30

答えて

0

以下のモジュールファイルを作成します。それは
Magentoの2.1.4に取り組んで作成します。アプリの\コード\ Sashas \ CustomerAttribute \ ETC \ module.xml

<?xml version="1.0" encoding="UTF-8"?> 

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> 
    <module name="Sashas_CustomerAttribute" setup_version="1.0.0"> 
     <sequence>   
      <module name="Magento_Customer"/> 
     </sequence> 
    </module> 
</config> 

作成:アプリの\コード\ Sashas \ CustomerAttributeセットアップ\ InstallData.php

<?php 
/** 
* @author  Sashas 
* @category Sashas 
* @package  Sashas_CustomerAttribute 
* @copyright Copyright (c) 2015 Sashas IT Support Inc. (http://www.extensions.sashas.org) 
*/ 

namespace Sashas\CustomerAttribute\Setup; 


use Magento\Customer\Setup\CustomerSetupFactory; 
use Magento\Customer\Model\Customer; 
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet; 
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory; 
use Magento\Framework\Setup\InstallDataInterface; 
use Magento\Framework\Setup\ModuleContextInterface; 
use Magento\Framework\Setup\ModuleDataSetupInterface; 



/** 
* @codeCoverageIgnore 
*/ 
class InstallData implements InstallDataInterface 
{ 

    /** 
    * @var CustomerSetupFactory 
    */ 
    protected $customerSetupFactory; 

    /** 
    * @var AttributeSetFactory 
    */ 
    private $attributeSetFactory; 

    /** 
    * @param CustomerSetupFactory $customerSetupFactory 
    * @param AttributeSetFactory $attributeSetFactory 
    */ 
    public function __construct(
     CustomerSetupFactory $customerSetupFactory, 
     AttributeSetFactory $attributeSetFactory 
    ) { 
     $this->customerSetupFactory = $customerSetupFactory; 
     $this->attributeSetFactory = $attributeSetFactory; 
    } 


    /** 
    * {@inheritdoc} 
    */ 
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) 
    { 

     /** @var CustomerSetup $customerSetup */ 
     $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); 

     $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); 
     $attributeSetId = $customerEntity->getDefaultAttributeSetId(); 

     /** @var $attributeSet AttributeSet */ 
     $attributeSet = $this->attributeSetFactory->create(); 
     $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); 

     $customerSetup->addAttribute(Customer::ENTITY, 'magento_username', [ 
      'type' => 'varchar', 
      'label' => 'Magento Username', 
      'input' => 'image', 
      'required' => false, 
      'visible' => true, 
      'user_defined' => true, 
      'sort_order' => 1000, 
      'position' => 1000, 
      'system' => 0, 
     ]); 

     $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'magento_username') 
     ->addData([ 
      'attribute_set_id' => $attributeSetId, 
      'attribute_group_id' => $attributeGroupId, 
      'used_in_forms' => ['adminhtml_customer'], 
     ]); 

     $attribute->save(); 


    } 
} 
\

登録:\ Sashas \ CustomerAttribute \

<?php 
     \Magento\Framework\Component\ComponentRegistrar::register(
      \Magento\Framework\Component\ComponentRegistrar::MODULE, 
      'Sashas_customerAttribute', 
      __DIR__ 
     ); 

?> 
+0

完全な回答をお願いしますか? – Jsparo30

関連する問題