Forums › Forums › OroCommerce › Price List Extension
This topic contains 19 replies, has 2 voices, and was last updated by fer_palacios 7 years, 5 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- November 7, 2016 at 3:00 pm #31311
Hi guys! How things?
I want to extend Price Lists in order to change the ownership of thus.
The goal is about that an user of a Business Unit could view and manage Price Lists owned by his BU, and restrict viewing and editing Price Lists of others Business Units.
In addition I want to be able to create ACLs through Roles, to do this dinamically.
Could you please give some orientation about this?
Thanks in advance.
H4
- CreatorTopic
- AuthorReplies
- November 14, 2016 at 8:10 am #31312
Hi guys!
I was trying to extend Price list so that they can manage the business unit, I tried different types of relationships, like being many to one, many to many etc.
But I only manage to generate the necessary tables and fields, but I can not show the owner of a price list in the UI.
Could anyone help me pleaseThanks in advance.
November 14, 2016 at 8:11 am #31313I share the code of different types of approach
November 14, 2016 at 8:13 am #31314PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950ENTITY/*** PriceList** @ORM\Table(name="oro_price_list")* @ORM\Entity* @Config*/class PriceList extends ExtendPriceList{/*** @var integer** @ORM\Id* @ORM\Column(type="integer")* @ORM\GeneratedValue(strategy="AUTO")*/protected $id;protected $owner;/*** @return int*/public function getId(){return $this->id;}/*** @return Owner*/public function getOwner(){return $this->owner;}/*** @param Owner $owner** @return $this*/public function setOwner(Owner $owner = null){$this->owner = $owner;return $this;}}November 14, 2016 at 8:14 am #31315PHP123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172Migrations -> Extension (PriceListExtension.php)use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface;use Oro\Bundle\EntityExtendBundle\Migration\OroOptions;use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper;/** @Configurable(* defaultValues={* "entity"={"label"="User", "plural_label"="Users"},* "ownership"={* "owner_type"="BUSINESS_UNIT",* "owner_field_name"="owner",* "owner_column_name"="business_unit_owner_id"* }* }* )*/class PriceListExtension implements ExtendExtensionAwareInterface{const PRICE_LIST_TABLE_NAME = 'oro_price_list';/** @var ExtendExtension */protected $extendExtension;/*** {@inheritdoc}*/public function setExtendExtension(ExtendExtension $extendExtension){$this->extendExtension = $extendExtension;}/*** Adds the association between the target table and the note table** @param Schema $schema* @param string $targetTableName Target entity table name* @param string $targetColumnName A column name is used to show related entity*/public function addPriceListAssociation(Schema $schema,$targetTableName,$targetColumnName = null) {$pricelist = $schema->getTable(self::PRICE_LIST_TABLE_NAME);$targetTable = $schema->getTable($targetTableName);if (empty($targetColumnName)) {$primaryKeyColumns = $targetTable->getPrimaryKeyColumns();$targetColumnName = array_shift($primaryKeyColumns);}$options = new OroOptions();$options->set('pricelist', 'enabled', true);$targetTable->addOption(OroOptions::KEY, $options);$associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName));$this->extendExtension->addManyToOneRelation($schema,$pricelist,$associationName,$targetTable,$targetColumnName);}}November 14, 2016 at 8:15 am #31316PHP123456789101112131415161718192021222324252627282930313233Migrations -> Schema -> v1_0use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface;use Oro\Bundle\MigrationBundle\Migration\Migration;use Oro\Bundle\MigrationBundle\Migration\QueryBag;use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;class ZymoPriceListBundle implements Migration, ExtendExtensionAwareInterface{protected $extendExtension;public function setExtendExtension(ExtendExtension $extendExtension){$this->extendExtension = $extendExtension;}public function up(Schema $schema, QueryBag $queries){$table = $schema->getTable('oro_price_list');$this->extendExtension->addManyToOneRelation($schema,$table,'id','oro_business_unit','owner',['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]);}}November 14, 2016 at 8:15 am #31317PHP123456789101112131415161718192021222324252627282930PriceListBundle -> Modelclass ExtendPriceList{/*** Constructor** The real implementation of this method is auto generated.** IMPORTANT: If the derived class has own constructor it must call parent constructor.*/public function __construct(){}public function supportTarget($targetClass){return false;}public function getTarget(){return null;}public function setTarget($target){return $this;}}November 14, 2016 at 8:16 am #31318YAML1234567891011121314151617181920212223242526Entity_config.ymlentity_config:pricelist:entity:items:# indicates whether the entity can have notes or notenabled: # booleanoptions:require_schema_update: truepriority: 250default_value: falseform:type: oro_entity_extend_association_choiceoptions:block: associationsrequired: truelabel: zymo.pricelist.enabledassociation_class: 'ZymoPriceListBundle:PriceList'# this attribute can be used to prohibit changing the note association state (no matter whether# it is enabled or not) for the entity# if TRUE than the current state cannot be changedimmutable: # booleanoptions:auditable: falseNovember 14, 2016 at 8:17 am #31319PHP1234567891011121314151617181920PriceListEntityConfigDumperExtension.phpclass PriceListEntityConfigDumperExtension extends AssociationEntityConfigDumperExtension{/*** {@inheritdoc}*/protected function getAssociationEntityClass(){return PriceList::ENTITY_NAME;}/*** {@inheritdoc}*/protected function getAssociationScope(){return 'pricelist';}}November 14, 2016 at 8:19 am #31320PHP123456789101112PriceListEntityGeneratorExtension.phpclass PriceListEntityGeneratorExtension extends AbstractAssociationEntityGeneratorExtension{/*** {@inheritdoc}*/public function supports(array $schema){return $schema['class'] === PriceList::ENTITY_NAME && parent::supports($schema);}}November 14, 2016 at 8:23 am #31321Second approach.
November 14, 2016 at 8:24 am #31322PHP123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293PriceListBundle -> Entity/*** PriceList** @ORM\Table(name="oro_price_list")* @ORM\Entity* @Config*/class PriceList extends ExtendPriceList{/*** @var integer** @ORM\Column(name="id", type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")*/private $id;/*** @var integer** @ORM\Column(name="owner", type="integer")*/private $owner;/*** @var integer** @ORM\Column(name="organization", type="integer")*/private $organization;/*** Get id** @return integer*/public function getId(){return $this->id;}/*** Set owner** @param integer $owner** @return PriceList*/public function setOwner($owner){$this->owner = $owner;return $this;}/*** Get owner** @return integer*/public function getOwner(){return $this->owner;}/*** Set organization** @param integer $organization** @return PriceList*/public function setOrganization($organization){$this->organization = $organization;return $this;}/*** Get organization** @return integer*/public function getOrganization(){return $this->organization;}}November 14, 2016 at 8:26 am #31323PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768Migrations -> ExtensionPriceListExtension.php/** @Configurable(* defaultValues={* "entity"={"label"="User", "plural_label"="Users"},* "ownership"={* "owner_type"="BUSINESS_UNIT",* "owner_field_name"="owner",* "owner_column_name"="business_unit_owner_id"* }* }* )*/class PriceListExtension implements ExtendExtensionAwareInterface{const PRICE_LIST_TABLE_NAME = 'oro_price_list';/** @var ExtendExtension */protected $extendExtension;/*** {@inheritdoc}*/public function setExtendExtension(ExtendExtension $extendExtension){$this->extendExtension = $extendExtension;}/*** Adds the association between the target table and the note table** @param Schema $schema* @param string $targetTableName Target entity table name* @param string $targetColumnName A column name is used to show related entity*/public function addPriceListAssociation(Schema $schema,$targetTableName,$targetColumnName = null) {$pricelist = $schema->getTable(self::PRICE_LIST_TABLE_NAME);$targetTable = $schema->getTable($targetTableName);if (empty($targetColumnName)) {$primaryKeyColumns = $targetTable->getPrimaryKeyColumns();$targetColumnName = array_shift($primaryKeyColumns);}$options = new OroOptions();$options->set('pricelist', 'enabled', true);$targetTable->addOption(OroOptions::KEY, $options);$associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName));$this->extendExtension->addManyToOneRelation($schema,$pricelist,$associationName,$targetTable,$targetColumnName);}}November 14, 2016 at 8:27 am #31324PHP12345678910111213141516171819202122232425262728293031323334353637Migrations -> Schema -> v1_0class ZymoPriceListBundle implements Migration, ExtendExtensionAwareInterface{protected $extendExtension;public function setExtendExtension(ExtendExtension $extendExtension){$this->extendExtension = $extendExtension;}public function up(Schema $schema, QueryBag $queries){$table = $schema->getTable('oro_price_list');$this->extendExtension->addManyToOneRelation($schema,$table,'id','oro_business_unit','owner',['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]);$table = $schema->getTable('oro_price_list');$this->extendExtension->addManyToOneRelation($schema,$table,'id','oro_organization','organization',['extend' => ['organization' => ExtendScope::OWNER_CUSTOM]]);}}November 14, 2016 at 8:28 am #31325PHP1234567891011121314151617181920212223242526272829PriceListBundle - >Modelclass ExtendPriceList{/*** Constructor** The real implementation of this method is auto generated.** IMPORTANT: If the derived class has own constructor it must call parent constructor.*/public function __construct(){}public function supportTarget($targetClass){return false;}public function getTarget(){return null;}public function setTarget($target){return $this;}}November 14, 2016 at 8:30 am #31326Third approach.
- AuthorReplies
The forum ‘OroCommerce’ is closed to new topics and replies.