Forums › Forums › OroCommerce › Price List Extension
This topic contains 19 replies, has 2 voices, and was last updated by fer_palacios 7 years, 4 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:32 am #31327PHP12345678910111213141516171819202122232425262728293031323334353637383940414243Entity/*** @ORM\Table(name="oro_price_list")* @ORM\Entity*/class PriceList extends ExtendPriceList{/*** @var integer** @ORM\Column(name="id", type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")*/private $id;/*** @ORM\ManyToMany(targetEntity="Oro\Bundle\OrganizationBundle\Entity\BusinessUnit")* @ORM\JoinTable(name="oro_price_list_owner",* joinColumns={@ORM\JoinColumn(name="price_list_id", referencedColumnName="id")},* inverseJoinColumns={@ORM\JoinColumn(name="owner_id", referencedColumnName="id")}* )*/private $owners;public function __construct() {$this->owners = new \Doctrine\Common\Collections\ArrayCollection();}/*** Get id** @return integer*/public function getId(){return $this->id;}}November 14, 2016 at 8:33 am #31328PHP12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667Migrations -> 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:34 am #31329PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344Migrations -> Schema -> v1_0class ZymoPriceListBundle implements Migration, ExtendExtensionAwareInterface{protected $extendExtension;public function setExtendExtension(ExtendExtension $extendExtension){$this->extendExtension = $extendExtension;}public function up(Schema $schema, QueryBag $queries){$this->createPLBUTemplateTable($schema);}/*** Create oro_price_list_owner table** @param Schema $schema*/protected function createPLBUTemplateTable(Schema $schema){$table = $schema->createTable('oro_price_list_owner');$table->addColumn('id', 'integer', ['autoincrement' => true]);$table->addColumn('price_list_id', 'integer', []);$table->addColumn('owner_id', 'integer', []);$table->setPrimaryKey(['id']);$table = $schema->getTable('oro_price_list_owner');$table->addForeignKeyConstraint($schema->getTable('oro_price_list'),['price_list_id'],['id'],[]);$table->addForeignKeyConstraint($schema->getTable('oro_business_unit'),['owner_id'],['id'],[]);}}November 14, 2016 at 8:35 am #31330PHP12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879PriceListBundle - >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(){}/*** Checks if an entity of the given type can be associated with this activity entity** The real implementation of this method is auto generated.** @param string $targetClass The class name of the target entity* @return bool*/public function supportPriceListTarget($targetClass){return false;}/*** Gets entities of the given type associated with this activity entity** The real implementation of this method is auto generated.** @param string $targetClass The class name of the target entity* @return object[]*/public function getPriceListTargets($targetClass){return null;}/*** Checks is the given entity is associated with this activity entity** The real implementation of this method is auto generated.** @param object $target Any configurable entity that can be associated with this activity** @return bool*/public function hasPriceListTarget($target){return false;}/*** Associates the given entity with this activity entity** The real implementation of this method is auto generated.** @param object $target Any configurable entity that can be associated with this activity* @return object This object*/public function addPriceListTarget($target){return $this;}/*** Removes the association of the given entity with this activity entity** The real implementation of this method is auto generated.** @param object $target Any configurable entity that can be associated with this activity* @return object This object*/public function removePriceListTarget($target){return $this;}}
- AuthorReplies
The forum ‘OroCommerce’ is closed to new topics and replies.