我想創建一個客戶圖像屬性,因此客戶和管理員可以上傳,更新和刪除像頭像等個人資料圖像。我知道如何在magento 1中可能,但不是在magento 2 。如果有人有任何想法,請分享。提前致謝。如何在magento 2上載客戶檔案圖像
0
A
回答
0
在模塊文件下面創建。它的工作對Magento的2.1.4
創建:應用程序\代碼\ Sashas \ CustomerAttribute \等\ 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 \ SETUP \ 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 \ registration.php的
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Sashas_customerAttribute',
__DIR__
);
?>
+0
你能否給出完整的答案? – Jsparo30
相關問題
- 1. 如何在Magento的圖像產品上重疊2張圖像?
- 2. 檔案圖像
- 3. 客戶檔案設計
- 4. 博客檔案
- 5. PHP:檔案系統像博客
- 6. 如何使用客戶端解決方案旋轉圖像
- 7. 如何在magento 2中保存客戶自定義屬性
- 8. 讓客戶在Magento
- 9. Magento 2訂單客戶組ID
- 10. 如何製作博客檔案
- 11. Magento 2:列出客戶或添加新客戶時出錯
- 12. 如何在imagemagick上上載圖像
- 13. 將客戶端上的圖像下載到zip
- 14. 在Magento 2中獲取圖像數據
- 15. 查看圖像上傳者客戶
- 16. 如何在Magento Checkout上提取客戶郵件Success.phtml 1.7
- 17. 如何在Magento上觸發客戶註冊電子郵件?
- 18. Magento:按名稱加載客戶羣
- 19. Magento EcomDev PHPUnit客戶裝置未加載
- 20. 通過ID加載客戶地址,Magento
- 21. 如何獲取圖像到客戶端?
- 22. 如何2個客戶端
- 23. fancyBox 2:在兩個方向上預加載圖像圖像
- 24. 上傳前壓縮客戶端圖像
- 25. 在Magento中使用FTP上載的圖像上獲取404
- 26. TSQL顯示博客檔案
- 27. 在VK.com上使用ActionScript加載個人檔案圖片
- 28. 客戶圖片在Magento上傳並調整大小
- 29. 如何在magento 2上傳擴展名
- 30. 使用APP在Facebook檔案圖像上添加水印
我,Hdid你得到一個解決方案嗎? – Jsparo30