Forums › Forums › OroCRM › OroCRM – How do I? Questions › How do i change the Ecommerce Statistics information to a specific user?
This topic contains 2 replies, has 3 voices, and was last updated by sfcable4seo 5 years, 1 month ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- May 3, 2018 at 5:04 am #29658
Hi everyone!
I wonder how i can change the Ecommerce Statistics widget so it only shows the information that the seller is responsible for.We have Magento integrated with OROcrm.
In Magento on the “Order” page we have a column that says “Sellers”. Our sellers use the dropdown menu to select themself as the seller and we can then filter it so the seller can see how much he/she has sold for.I want the seller to be able to see this info on the Ecommerce Statistics widget.
Does anyone have an ide on how to fix this?
At the moment we only get all the orders but i would like to sort it up so the seller can view their own orders in Ecommerce Statistics widget.Thank you and have a nice day!
- CreatorTopic
- AuthorReplies
- May 3, 2018 at 8:29 am #29660
Hello, oliver3.
To do this, you can create your own widget based on the Ecommerce Statistics widget and modify queries that select data.
For example, if MagentoOrder entity have one-to-many relation to user and this relation called sellers, the code you have to implement may be the next:
– create own class MagentoSellerBigNumberProvider that extends MagentoBigNumberProvider in your bundle (in my example i use Acme\DemoBundle):
PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889<?phpnamespace Acme\DemoBundle\Provider;use Doctrine\ORM\QueryBuilder;use Oro\Bundle\MagentoBundle\Provider\MagentoBigNumberProvider;use Oro\Bundle\SecurityBundle\Authentication\TokenAccessorInterface;class MagentoSellerBigNumberProvider extends MagentoBigNumberProvider{/** @var TokenAccessorInterface */protected $tokenAccessor;/*** @param TokenAccessorInterface $tokenAccessor*/public function setTokenAccessor(TokenAccessorInterface $tokenAccessor){$this->tokenAccessor = $tokenAccessor;}/*** {@inheritdoc*/public function getRevenueValues($dateRange){list($start, $end) = $this->dateHelper->getPeriod($dateRange, 'OroMagentoBundle:Order', 'createdAt');$qb = $this->getOrderRepository()->getRevenueValueQB();$this->applyDateFiltering($qb, 'orders.createdAt', $start, $end);$this->addSellerLimitationToQuery($qb);$value = $this->aclHelper->apply($qb)->getOneOrNullResult();return $value['val'] ? : 0;}/*** {@inheritdoc*/public function getOrdersNumberValues($dateRange){list($start, $end) = $this->dateHelper->getPeriod($dateRange, 'OroMagentoBundle:Order', 'createdAt');$qb = $this->getOrderRepository()->getOrdersNumberValueQB();$this->applyDateFiltering($qb, 'o.createdAt', $start, $end);$this->addSellerLimitationToQuery($qb);$value = $this->aclHelper->apply($qb)->getOneOrNullResult();return $value['val'] ? : 0;}/*** {@inheritdoc*/public function getAOVValues($dateRange){list($start, $end) = $this->dateHelper->getPeriod($dateRange, 'OroMagentoBundle:Order', 'createdAt');$qb = $this->getOrderRepository()->getAOVValueQB();$this->applyDateFiltering($qb, 'o.createdAt', $start, $end);$this->addSellerLimitationToQuery($qb);$value = $this->aclHelper->apply($qb)->getOneOrNullResult();return $value['ordersCount'] ? $value['revenue'] / $value['ordersCount'] : 0;}/*** {@inheritdoc*/public function getDiscountedOrdersPercentValues($dateRange){list($start, $end) = $this->dateHelper->getPeriod($dateRange, 'OroMagentoBundle:Order', 'createdAt');$qb = $this->getOrderRepository()->getDiscountedOrdersPercentQB();$this->applyDateFiltering($qb, 'o.createdAt', $start, $end);$this->addSellerLimitationToQuery($qb);$value = $this->aclHelper->apply($qb)->getOneOrNullResult();return $value['allOrders'] ? $value['discounted'] / $value['allOrders'] : 0;}/*** @param QueryBuilder $qb*/protected function addSellerLimitationToQuery(QueryBuilder $qb){$qb->andWhere($qb->expr()->in('o.sellers', ':sellers'))->setParameter('sellers', [$this->tokenAccessor->getUser()]);}}At this class i rewrite some of metrics methods from the parent class and add the limitation on seller relation with addSellerLimitationToQuery function.
– register this class as new big number (the type of widget) provider. In my example, the alias of this provider will be magento_seller:
YAML1234567891011oro_magento.provider.big_number_seller:class: Acme\DemoBundle\Provider\MagentoSellerBigNumberProviderarguments:- "@doctrine"- "@oro_security.acl_helper"- "@oro_dashboard.provider.big_number.date_helper"- "@oro_magento.provider.website_visit"calls:- ['setTokenAccessor', ['@oro_security.token_accessor']]tags:- { name: oro_dashboard.big_number.provider, alias: magento_seller }– Add new widget declaration in dashboards.yml file. This widget is a copy of big_numbers_widget widget but with another label and data_provider parameters in items:
YAML123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293big_numbers_widget_seller:label: Ecommerce Seller statisticsroute: oro_dashboard_itemized_data_widgetroute_parameters: { bundle: OroDashboardBundle, name: bigNumbers }acl: oro_magento_cart_viewdescription: oro.magento.dashboard.e_commerce_statistic.descriptionicon: bundles/oromagento/img/icon-big_numbers.pngapplicable: "@oro_magento.provider.enitity_state->isEntityCartEnabled()"data_items:revenue:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getRevenueValues, currency)"label: oro.magento.dashboard.e_commerce_statistic.revenue.labelacl: oro_magento_order_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigorders_number:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getOrdersNumberValues, integer)"label: oro.magento.dashboard.e_commerce_statistic.orders_number.labelacl: oro_magento_order_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigdiscounted_orders_percent:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getDiscountedOrdersPercentValues, percent)"label: oro.magento.dashboard.e_commerce_statistic.discounted_orders_percent.labelacl: oro_magento_order_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twignew_customers_count:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getNewCustomersCountValues, integer)"label: oro.magento.dashboard.e_commerce_statistic.new_customers_count.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigreturning_customers_count:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getReturningCustomersCountValues, integer)"label: oro.magento.dashboard.e_commerce_statistic.returning_customers_count.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigaverage_order_value:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getAOVValues, currency)"label: oro.magento.dashboard.e_commerce_statistic.average_order_value.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigabandoned_revenue:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getAbandonedRevenueValues, currency, true)"label: oro.magento.dashboard.e_commerce_statistic.abandoned_revenue.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigabandoned_count:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getAbandonedCountValues, integer, true)"label: oro.magento.dashboard.e_commerce_statistic.abandoned_count.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigabandon_rate:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getAbandonRateValues, percent, true)"label: oro.magento.dashboard.e_commerce_statistic.abandon_rate.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigsite_visits:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getSiteVisitsValues, integer)"label: oro.magento.dashboard.e_commerce_statistic.site_visits.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigorder_conversion:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getOrderConversionValues, percent)"label: oro.magento.dashboard.e_commerce_statistic.order_conversion.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigcustomer_conversion:data_provider: "@oro_dashboard.provider.big_number.processor->getBigNumberValues($widgetOptions$, magento_seller, getCustomerConversionValues, percent)"label: oro.magento.dashboard.e_commerce_statistic.customer_conversion.labelacl: oro_magento_customer_viewtemplate: OroDashboardBundle:Dashboard:bigNumberSubwidget.html.twigconfiguration:dateRange:type: Oro\Bundle\DashboardBundle\Form\Type\WidgetDateRangeTypeoptions:label: oro.dashboard.date_range.labelvalue_types: trueshow_on_widget: trueusePreviousInterval:type: Oro\Bundle\DashboardBundle\Form\Type\WidgetPreviousDateRangeTypeoptions:label: oro.dashboard.previous_date_range.labelrequired: falseconverter_attributes:dateRangeField: dateRangedefault_checked: truesubWidgets:type: Oro\Bundle\DashboardBundle\Form\Type\WidgetItemsTypeoptions:label: oro.dashboard.widget.big_number.metricsattr:placeholder: oro.dashboard.widget.big_number.choose_metrics_placeholderitem_label: oro.dashboard.widget.big_number.metricNamerequired: falsewidget_name: big_numbers_widget– Clear the cache.
After that, you will be able to add new widget with title Ecommerce Seller statistics at your dashboard as well as standart Ecommerce Statistics widget.
March 4, 2019 at 11:23 pm #38270thanks
- AuthorReplies
The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.