After added new custom column in magento 2 filter not working for date sorting - magento-2.0

I have added new column in sales order for coupon code. after added this column sorting working fine but when i am filtering for last day order it is showing something went wrong.
the ajax issue is in 'mui/index/render'
app\code\Vicomage\CustomCoupon\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="sales_order_grid_data_source" xsi:type="string">Vicomage\CustomCoupon\Model\ResourceModel\Order\Grid\Collection</item>
</argument>
</arguments>
</type>
</config>
app\code\Vicomage\CustomCoupon\etc\module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vicomage_CustomCoupon" setup_version="2.0.0">
</module>
</config>
app\code\Vicomage\CustomCoupon\Model\ResourceModel\Order\Grid\Collection.php
<?php
namespace Vicomage\CustomCoupon\Model\ResourceModel\Order\Grid;
use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OriginalCollection;
class Collection extends OriginalCollection{
protected function _renderFiltersBefore()
{
$joinTable = $this->getTable('sales_order');
$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id = sales_order.entity_id', ['coupon_code']);
parent::_renderFiltersBefore();
}
}
app\code\Vicomage\CustomCoupon\view\adminhtml\ui_component\sales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_columns">
<column name="coupon_code">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>

add below lines of code before parent::_renderFiltersBefore() in your file app\code\Vicomage\CustomCoupon\Model\ResourceModel\Order\Grid\Collection.php
$this->getSelect()->group('main_table.entity_id');
$this->getSelect()->group('main_table.store_id');
let me know if you still facing same issue.

Related

Show custom query data in Magento 2 admin grid

I have created a custom module which stores some data related to the product in a custom collection.
Now to show it as a report in the Magento 2 admin, I need to create a custom query to join it with the customer and product tables and do some aggregate functionality such as count grouped by the product.
Is there a way we can do that using custom SQL query and pass the whole result in the grid and it takes the relevant column names and shows it in the grid?
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">bargain_offer_listing.bargain_offer_listing_data_source</item>
<item name="deps" xsi:type="string">bargain_offer_listing.bargain_offer_listing_data_source</item>
<item name="spinner" xsi:type="string">bargain_offer_listing_columns</item>
</item>
</argument>
<listingToolbar name="listing_top">
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filterSearch name="fulltext"/>
<filters name="listing_filters"/>
<paging name="listing_paging"/>
</listingToolbar>
<dataSource name="bargain_offer_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">MyModule\Bargain\Ui\DataProvider\OfferListingProvider
</argument>
<argument name="name" xsi:type="string">bargain_offer_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">entity_id</argument>
<argument name="requestFieldName" xsi:type="string">entity_id</argument>
<argument name="data" xsi:type="array">
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">entity_id</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="bargain_offer_listing_columns">
<column name="entity_id">
<settings>
<filter>textRange</filter>
<label translate="true">ID</label>
</settings>
</column>
<column name="product_sku">
<settings>
<filter>text</filter>
<label translate="true">Product Sku</label>
</settings>
</column>
<column name="product_name">
<settings>
<filter>text</filter>
<bodyTmpl>ui/grid/cells/text</bodyTmpl>
<label translate="true">Product Name</label>
</settings>
</column>
<column name="number_of_buyers">
<settings>
<filter>text</filter>
<label translate="true">No of buyers</label>
</settings>
</column>
<column name="times_bought">
<settings>
<filter>text</filter>
<label translate="true">Times Bought</label>
</settings>
</column>
</columns>
</listing>
This is my data provider class
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider;
class OfferListingProvider extends DataProvider
{
}
But I do not know how to utilize this. Any suggestions or guides is appreciated.

Magento2 Newsletter Grid custom column filter not working

I have added new column in newsletter grid in Magento2.2.5 with override newsletter_subscriber_block.xml in my custom module, but somehow filter is not working for new column. Please find below code of newsletter grid i have override in my custom module..
<referenceBlock name="adminhtml.newslettrer.subscriber.grid.columnSet">
<block class="Magento\Backend\Block\Widget\Grid\Column">
<arguments>
<argument name="header" xsi:type="string" translate="true">Urgency</argument>
<argument name="index" xsi:type="string">urgency</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="array">
<item name="withinweek" xsi:type="array">
<item name="value" xsi:type="string">1</item>
<item name="label" xsi:type="string" translate="true">With in 3 Weeks</item>
</item>
<item name="afterweek" xsi:type="array">
<item name="value" xsi:type="string">0</item>
<item name="label" xsi:type="string" translate="true">After 3 Weeks</item>
</item>
</argument>
<argument name="header_css_class" xsi:type="string">col-urgency</argument>
<argument name="column_css_class" xsi:type="string">col-urgency</argument>
</arguments>
</block>
</referenceBlock>

Custom css added to page.xml in Magento is not loading

I have a custom css.I have placed it in the theme that we are using - skin\frontend\my-theme\default\css\custom.css
Now I have called this file in page.xml - app/design/frontend/my-theme/default/layout/page.xml
Syntax:
<layout version="0.1.0">
<default translate="label" module="page">
<block type="page/html_head" name="head" as="head">
<action method="addCss"><stylesheet>css/custom.css</stylesheet></action>
</block>
</default>
</layout>
When I check view source, I don't see my custom.css.
Can you tell me what is wrong and how I get get to work custom.css?
You should try :
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="head">
<!-- /skin/frontend/yourpackage/yourtheme/css/custom.css -->
<action method="addItem"><type>skin_css</type><name>css/custom.css</name><params/></action>
</reference>
</default>
</layout>
Or :
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="head">
<!-- /skin/frontend/yourpackage/yourtheme/css/custom.css -->
<action method="addCss"><stylesheet>css/custom.css</stylesheet></action>
</reference>
</default>
</layout>
When you want to insert something in an existing bloc, you have to use "reference" tag. Put the block name in the "name" attribute.
You can now add everything you want to your existing block (like childs, css, templates...).

Error when saving document of custom type in Alfresco Share

I got this exception when trying to save a new document of custom type:
org.alfresco.service.cmr.repository.MalformedNodeRefException: 06010026 Invalid node ref - does not contain forward slash: {node.nodeRef}
Here is how the definition of the custom type looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Definition of new Model -->
<model name="ht:channelmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<!-- Imports are required to allow references to definitions in other models
-->
<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
</imports>
<!-- Introduction of new namespaces defined by this model -->
<namespaces>
<namespace uri="http://www.someco.com/model/content/1.0" prefix="ht" />
</namespaces>
<types>
<!-- Here comes my type -->
<type name="ht:doc">
<title>Custom Document</title>
<parent>cm:content</parent>
<mandatory-aspects>
<aspect>cm:generalclassifiable</aspect>
</mandatory-aspects>
</type>
</types>
<aspects>
<aspect name="ht:channel">
<title>Content Channel</title>
<properties>
<property name="ht:isWeb">
<type>d:boolean</type>
</property>
</properties>
</aspect>
</aspects>
</model>
and here is how I set the forms for displaying the creation of a new document of my custom type (inside share-config-custom.xml)
<alfresco-config>
<config evaluator="string-compare" condition="DocumentLibrary">
<create-content>
<content id="plain-text" mimetype="text/plain" label="Prompt" itemid="ht:doc" />
</create-content>
<aspects>
<visible>
<aspect name="ht:channel" />
</visible>
<addable>
</addable>
<removeable>
</removeable>
</aspects>
<types>
<type name="cm:content">
<subtype name="ht:doc" />
</type>
</types>
</config>
<config evaluator="model-type" condition="ht:doc">
<forms>
<form>
<field-visibility>
<show id="cm:title" force="true" />
<show id="ht:isWeb" force="true" />
</field-visibility>
<appearance>
<field id="cm:title">
<control template="/org/alfresco/components/form/controls/textfield.ftl" />
</field>
</appearance>
</form>
</forms>
</config>
</alfresco-config>
Is it something wrong with the formatting or am I missing some fields in the type definition?
Thanks
Found the solution on the dedicated Alfresco forum.
Here it is:
<content id="myContent" label="Prompt" type="pagelink" index="1" >
<param name="page">create-content?destination={nodeRef}&itemId=ht:doc&mimeType=text/html</param>
</content>

ASCX Web Controls are not stored in Database

Recently we have upgraded to Tridion 2011 SP1 from Tridion 5.3.
In our existing implementation we have various Dynamic Component Templates. For few CTs output format is ASCX Web Control for few CTs output format is HTML Fragment.
After publishing we came across
1) ASCX WebControls are NOT stored to Storage Database (SQLServer). In Tridion 5.3 they were.
2) HTML Fragments are getting stored in database.
In our implementation binary files, page, embedded component templates are stored on file system and Dynamic component templates are stored in SQL Sever database.
We think we have missed something in our cd_storage_config. Please find attached config file.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration Version="6.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schemas/cd_storage_conf.xsd">
<Global>
<ObjectCache Enabled="false">
<Policy Type="LRU" Class="com.tridion.cache.LRUPolicy">
<Param Name="MemSize" Value="16mb"/>
</Policy>
<Features>
<Feature Type="DependencyTracker" Class="com.tridion.cache.DependencyTracker"/>
</Features>
</ObjectCache>
<Storages>
<Storage Type="persistence" Id="sqlserver" dialect="MSSQL" Class="com.tridion.storage.persistence.JPADAOFactory">
<Pool Type="jdbc" Size="5" MonitorInterval="60" IdleTimeout="120" CheckoutTimeout="120" />
<DataSource Class="com.microsoft.sqlserver.jdbc.SQLServerDataSource">
<Property Name="serverName" Value="local" />
<Property Name="portNumber" Value="1433" />
<Property Name="databaseName" Value="TridionBroker" />
<Property Name="user" Value="TridionBrokerUser" />
<Property Name="password" Value="mypass" />
</DataSource>
</Storage>
<Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="defaultFile" defaultFilesystem="false">
<Root Path="d:\Inetpub\MyPortal" />
</Storage>
<Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="defaultDataFile" defaultFilesystem="true" defaultStorage="true">
<Root Path="d:\Inetpub\MyPortal\data" />
</Storage>
<SearchFilter Name="SearchFilter" Class="com.tridion.broker.components.meta.MsSqlSearchFilterHome" defaultStorageId="sqlserver"/>
</Storages>
</Global>
<ItemTypes defaultStorageId="defaultDataFile" cached="false">
<Item typeMapping="Query" storageId="sqlserver"/>
<Item typeMapping="Page" cached="false" storageId="defaultFile"/>
<Item typeMapping="Binary" cached="false" storageId="defaultFile"/>
<Item typeMapping="ComponentPresentation" itemExtension=".Jsp" storageId="sqlserver"/>
<Item typeMapping="ComponentPresentation" itemExtension=".Asp" storageId="sqlserver"/>
<Item typeMapping="ComponentPresentation" itemExtension=".Xml" storageId="sqlserver"/>
<Item typeMapping="ComponentPresentation" itemExtension=".Txt" storageId="sqlserver"/>
<Item typeMapping="Metadata" cached="true" storageId="sqlserver"/>
<Item typeMapping="XSLT" cached="true" storageId="sqlserver"/>
</ItemTypes>
<License Location="d:\Tridion\config\cd_licenses.xml"/>
You don't have any ascx binding in your storage config. In 5.3, it used to be Asp binding.
Change the following:
<Item typeMapping="ComponentPresentation" itemExtension=".Asp" storageId="sqlserver"/>
To:
<Item typeMapping="ComponentPresentation" itemExtension=".ascx" storageId="sqlserver"/>
Also, in tridion 2011 you don't need to specify mapping for each type (like txt, jsp etc..) if you want all to be stored in db.
You can simply do this:
<Item typeMapping="ComponentPresentation" storageId="sqlserver"/>

Resources