Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. $attributes['custom_country'] = [
  2. 'group' => 'General',
  3. 'type' => 'int',
  4. 'label' => 'Country',
  5. 'input' => 'select',
  6. 'source' => VendorModuleModelResourceModelAttributeSourceCountry::class,
  7. 'global' => ScopedAttributeInterface::SCOPE_STORE,
  8. 'required' => '0',
  9. 'user_defined' => false,
  10. 'default' => '',
  11. 'unique' => false,
  12. 'position' => '50',
  13. 'note' => '',
  14. 'visible' => '1',
  15. 'wysiwyg_enabled' => '0',
  16. ];
  17.  
  18. <?php
  19. /**
  20. * Copyright © Magento, Inc. All rights reserved.
  21. * See COPYING.txt for license details.
  22. */
  23.  
  24. namespace VendorModuleModelResourceModelAttributeSource;
  25.  
  26. class Custom extends MagentoEavModelEntityAttributeSourceTable {
  27. /**
  28. * @var MagentoEavModelConfig
  29. */
  30. protected $eavConfig;
  31.  
  32. /**
  33. * [__construct description]
  34. * @param MagentoEavModelResourceModelEntityAttributeOptionCollectionFactory $attrOptionCollectionFactory [description]
  35. * @param MagentoEavModelResourceModelEntityAttributeOptionFactory $attrOptionFactory [description]
  36. * @param MagentoEavModelConfig $eavConfig [description]
  37. */
  38. public function __construct(
  39. MagentoEavModelResourceModelEntityAttributeOptionCollectionFactory $attrOptionCollectionFactory,
  40. MagentoEavModelResourceModelEntityAttributeOptionFactory $attrOptionFactory,
  41. MagentoEavModelConfig $eavConfig
  42. ) {
  43. $this->eavConfig = $eavConfig;
  44. parent::__construct($attrOptionCollectionFactory, $attrOptionFactory);
  45. }
  46.  
  47. public function getAllOptions($withEmpty = true, $defaultValues = false) {
  48. $attribute = $this->eavConfig->getAttribute('custom_eav_entity', 'attr_code');
  49. return $attribute->getSource()->getAllOptions($withEmpty,$defaultValues); // here returns error
  50. }
  51.  
  52. public function getOptionsArray($withEmpty = true) {
  53. $options = [];
  54. foreach ($this->getAllOptions($withEmpty) as $option) {
  55. $options[$option['value']] = $option['label'];
  56. }
  57. return $options;
  58. }
  59. }
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement