Create Custom Order Attribute - mysql

In my module (name = pay), I am trying to create a custom attribute in orders, but my code does not work.
My file pay_setup/mysql4-install-1.0.0.php
$installer = new Mage_Sales_Model_Mysql4_Setup;
$installer->startSetup();
$attribute = array(
'type' => 'text',
'backend_type' => 'text',
'frontend_input' => 'text',
'is_user_defined' => true,
'label' => 'My Attr',
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'default' => ''
);
$installer->addAttribute('order', 'myattr', $attribute);
$installer->endSetup();
My config.xml
<?xml version="1.0"?>
<config>
<modules>
<Myspacework_Pay>
<version>1.0.0</version>
</Myspacework_Pay>
</modules>
<frontend>
<routers>
<pay>
<use>standard</use>
<args>
<module>Myspacework_Pay</module>
<frontName>pay</frontName>
</args>
</pay>
</routers>
<layout>
<updates>
<pay>
<file>pay.xml</file>
</pay>
</updates>
</layout>
</frontend>
<global>
<fieldsets>
<sales_convert_quote_payment>
<celphone_no>
<to_order_payment>*</to_order_payment>
</celphone_no>
</sales_convert_quote_payment>
</fieldsets>
<models>
<pay>
<class>Myspacework_Pay_Model</class>
<resourceModel>pay_mysql4</resourceModel>
</pay>
</models>
<resources>
<pay_setup>
<setup>
<module>Myspacework_Pay</module>
<class>Mage_Sales_Model_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</pay_setup>
<pay_write>
<connection>
<use>core_write</use>
</connection>
</pay_write>
<pay_read>
<connection>
<use>core_read</use>
</connection>
</pay_read>
</resources>
<blocks>
<pay>
<class>Myspacework_Pay_Block</class>
</pay>
</blocks>
<helpers>
<pay>
<class>Myspacework_Pay_Helper</class>
</pay>
</helpers>
</global>
<default>
<payment>
<pay>
<active>1</active>
<model>pay/standard</model>
</pay>
</payment>
</default>
</config>
I found no trace of "my attr" in the database.
Any idea?

I got it
$installer = $this;
$installer->startSetup();
$installer->addAttribute('order_payment', 'my_attr', array());
$installer->endSetup();
How to set data in my attr.
$order->getPayment()->setMyAttr(utf8_encode($data));
$order->getPayment()->save();

Related

Getting Error While trying to Setup MySql Datasource in JBOSS EAP 7.4

Getting the below mentioned error everytime I run the server.
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "MySqlDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => [
"jboss.jdbc-driver.mysql",
"jboss.jdbc-driver.mysql"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/MySqlDS is missing [jboss.jdbc-driver.mysql]",
"org.wildfly.data-source.MySqlDS is missing [jboss.jdbc-driver.mysql]",
"org.wildfly.data-source.MySqlDS is missing [jboss.jdbc-driver.mysql]"
]
}
I am trying to setup MySql datasource with JNDI in JBOSS EAP 7.4.
I have created the module.xml and put the mysql-connector jar inside com/mysql/main folder.
<?xml version='1.0' encoding='UTF-8'?>
<module xmlns="urn:jboss:module:1.9" name="com.mysql">
<properties>
<property name="jboss.api" value="unsupported"/>
</properties>
<resources>
<resource-root path="mysql-connector-java-8.0.30.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
Also have added the datasource details in standalone.xml file and also added the driver in driver tags.
<subsystem xmlns="urn:jboss:domain:datasources:6.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/bookshopdb</connection-url>
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
<driver>mysql</driver>
<new-connection-sql>SELECT 1</new-connection-sql>
<pool>
<min-pool-size>0</min-pool-size>
<max-pool-size>10</max-pool-size>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<validate-on-match>true</validate-on-match>
</validation>
</datasource>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>

Backend Module for Magento 1.9.x

i want to build a new module for Magento 1.9.4 that will be shown in the Admin area (catalog).
I programmed the following code, but i dont know how to show this module in the backend (including form tags). I just get a 404 error.
Here is my code with which i started my first module:
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Eron_ChangePricesPerCategory>
<version>0.1.0</version>
</Eron_ChangePricesPerCategory>
</modules>
<frontend>
<routers>
<changepricespercategory>
<use>standard</use>
<args>
<module>Eron_ChangePricesPerCategory</module>
<frontName>changepricespercategory</frontName>
</args>
</changepricespercategory>
</routers>
</frontend>
<admin>
<routers>
<changepricespercategory>
<use>admin</use>
<args>
<module>Eron_ChangePricesPerCategory</module>
<frontName>admin_changepricespercategory</frontName>
</args>
</changepricespercategory>
</routers>
</admin>
<global>
<helpers>
<changepricespercategory>
<class>Eron_ChangePricesPerCategory_Helper</class>
</changepricespercategory>
</helpers>
</global>
<adminhtml>
<layout>
<updates>
<eron_changepricespercategory>
<file>eron_changepricespercategory.xml</file>
</eron_changepricespercategory>
</updates>
</layout>
</adminhtml>
</config>
adminhtml.xml
<?xml version="1.0"?>
<config>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<changepricespercategory_settings translate="title">
<title>Extra Fee Settings</title>
<sort_order>55</sort_order>
</changepricespercategory_settings>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
system.xml
<?xml version="1.0"?>
<config>
<sections>
<changepricespercategory translate="label" module="changepricespercategory">
<label>Artikelpreise pro Kategorie ändern</label>
<tab>catalog</tab>
<frontend_type>text</frontend_type>
<sort_order>999</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<active translate="label">
<label>Aktiviert</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</active>
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</title>
<name translate="label">
<label>Name</label>
<frontend_type>text</frontend_type>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</name>
<showmethod translate="label">
<label>Versandart zeigen, auch wenn nicht möglich</label>
<frontend_type>select</frontend_type>
<sort_order>50</sort_order>
<source_model>adminhtml/system_config_source_yesno</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</showmethod>
<specificerrmsg translate="label">
<label>Angezeigte Fehlermeldung</label>
<frontend_type>textarea</frontend_type>
<sort_order>60</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</specificerrmsg>
<sort_order translate="label">
<label>Reihenfolge</label>
<frontend_type>text</frontend_type>
<sort_order>70</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</sort_order>
</fields>
</changepricespercategory>
</sections>
</config>
IndexController.php (in controllers/Adminhtml)
<?php
class Eron_ChangePricesPerCategory_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action {
/**
* Admin controller index action
*
* #access public
* #return void
*/
public function indexAction() {
$Block = $this->getLayout()->createBlock('changepricespercategory/Adminhtml_changepricespercategory');
$this->loadLayout()
->_addContent($Block)
->renderLayout();
}
}
The Module is shown in the backend... But i when i click on it, I get a 404. Can anybody help me? Maybe there is a good documentation - im new to magento module developement.
More Information: I want to build a module for changing all prices of a category by a percentage (e.g 2% increase).
You can get started from this toturial:
https://bsscommerce.com/confluence/3-simple-steps-to-create-admin-grid-in-magento-1/
If you want to try more features check this one:
https://www.codealist.com/magento-1-9-x-create-an-adminhtml-controller/

How can I make my enable or disable dropdown box work for my custom extension?

I have made a query extension where you can ask your query, and then get a reply from admin. And I have already managed to get the extension setting tab added as a tab in the admin configuration area, and created "Product Query" menu also.
successfully created this tab
Here are all of my files :)
app/code/local/Vlabs/Productquery/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Vlabs_Productquery>
<version>0.1.0</version>
</Vlabs_Productquery>
</modules>
<frontend>
<routers>
<productquery>
<use>standard</use>
<args>
<module>Vlabs_Productquery</module>
<frontName>productquery</frontName>
</args>
</productquery>
</routers>
<layout>
<updates>
<productquery module="Vlabs_Productquery">
<file>productquery.xml</file>
</productquery>
</updates>
</layout>
</frontend>
<global>
<blocks>
<productquery>
<class>Vlabs_Productquery_Block</class>
</productquery>
</blocks>
<models>
<productquery>
<class>Vlabs_Productquery_Model</class>
<resourceModel>productquery_Resource</resourceModel>
</productquery>
<productquery_Resource>
<class>Vlabs_Productquery_Model_Resource</class>
<entities>
<querybox>
<table>Vlabs_queryBox</table>
</querybox>
</entities>
</productquery_Resource>
</models>
<helpers>
<productquery>
<class>Vlabs_Productquery_Helper</class>
</productquery>
</helpers>
<resources>
<form_setup>
<setup>
<module>Vlabs_Productquery</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</form_setup>
<form_write>
<connection>
<use>core_write</use>
</connection>
</form_write>
<form_read>
<connection>
<use>core_read</use>
</connection>
</form_read>
</resources>
<template>
<email>
<vlabs_query_email_template translate="label">
<label>Recurring order email</label>
<file>vlabs_querybox_email.html</file>
<type>html</type>
</vlabs_query_email_template>
</email>
</template>
</global>
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<modules>
<Vlabs_Productquery before="Mage_Adminhtml">Vlabs_Productquery_Adminhtml</Vlabs_Productquery>
</modules>
<frontname>productquery</frontname>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<productquery>
<file>productquery.xml</file>
</productquery>
</updates>
</layout>
</adminhtml>
</config>
app/code/local/Vlabs/Productquery/etc/adminhtml.xml
<config>
<menu>
<productquery>
<title>Product Query</title>
<sort_order>50</sort_order>
<children>
<query>
<title>Query</title>
<sort_order>1</sort_order>
<action>adminhtml/index/</action>
</query>
<settings>
<title>Settings</title>
<sort_order>2</sort_order>
<action>adminhtml/index/settings</action>
</settings>
</children>
</productquery>
</menu>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<productquery>
<title>Beckin Drop Down Shipping Extension</title>
</productquery>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
app/code/local/Vlabs/Productquery/etc/system.xml
<?xml version="1.0"?>
<config>
<tabs>
<productquery translate="label">
<label>Vyrazu Query Extension</label>
<sort_order>100</sort_order>
</productquery>
</tabs>
<sections>
<productquery translate="label" module="productquery">
<label>Query</label>
<tab>productquery</tab>
<frontend_type>text</frontend_type>
<sort_order>1000</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<settings translate="label" module="productquery">
<label>Settings</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<enable translate="label">
<label>Enable</label>
<comment>
<![CDATA[Enable or Disable this extension.]]>
</comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enable>
</fields>
</settings>
</groups>
</productquery>
</sections>
</config>
Please guide me, where I should write those code,by this i can disable or enable this extension with this disable/enable dropdown.
I solved the issue.May be someone will be helpfull by this answer. That's why I update my answer.
So,at first write this anywhere to check it is working or not
$enableorDisable = Mage::getStoreConfig('productquery/settings/enable',Mage::app()->getStore());
print_r($enableorDisable); die();
if answer is 0 when your module is disable and answer is 1, when your module is enable. then it is working fine.. And you have to add following line in your block.
<action method="setTitle" translate="value" ifconfig="productquery/settings/enable"><value>Product Query</value></action>
add ifconfig="modulename/group name/field name"
Thank You..

add new column to install script in magento CMS Page

So i am down to the last bit of my module and it's really annoying i can't get it to add a new column to the CMS_PAGE table.
This is what i have so far:
/app/code/local/Damian/CMS/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<damian_cms>
<version>0.1.0</version> <!-- Version of module -->
</damian_cms>
</modules>
<global>
<models>
<damian_cms>
<class>Damian_CMS_Model</class>
<resourceModel>cms_mysql4</resourceModel>
</damian_cms>
</models>
<events>
<adminhtml_cms_page_edit_tab_content_prepare_form>
<observers>
<damian_page_edit_tab_content>
<type>singleton</type>
<class>Damian_CMS_Model_Observer</class>
<method>cmsField</method>
</damian_page_edit_tab_content>
</observers>
</adminhtml_cms_page_edit_tab_content_prepare_form>
<cms_page_prepare_save>
<observers>
<damian_cms_save_page>
<type>singleton</type>
<class>Damian_CMS_Model_Observer</class>
<method>savePage</method>
</damian_cms_save_page>
</observers>
</cms_page_prepare_save>
</events>
<resources>
<damian_cms_setup>
<setup>
<module>damian_cms</module>
<class>Damian_CMS_Model_Resource_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</damian_cms_setup>
<cms_write> <!-- It gives the write permission to db -->
<connection>
<use>core_write</use>
</connection>
</cms_write>
<cms_read> <!-- It gives the read permission from db -->
<connection>
<use>core_read</use>
</connection>
</cms_read>
</resources>
</global>
</config>
/app/code/local/Damian/CMS/Model/Resource/Setup.php
<?php
class Damian_CMS_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
}
/app/code/local/Damian/CMS/sql/cms_setup/mysql-install-0.1.0.php
<?php
$installer = $this;
/* #var $installer Mage_Core_Model_Resource_Setup */
echo 'Running This Upgrade:';
die("Exit for now");
$installer->startSetup();
$tableName = $installer->getTable('cms_page');
$installer->getConnection()->addColumn($tableName, 'cms_sitemap', array(
'nullable' => true,
'length' => 255,
'default' => 1,
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
'comment' => 'added from extension Damian CMS'
));
$installer->endSetup();
I haven't added the rest becuase it all seems to work, but i neeed this install script to work so i can put it into production on the live server, this is local and i have access to my own MYSQL database, But on the live servers i won't have access to the MYSQL database so i have to get this script to work.
Thanks for your help :)
ok so i got it to work!
I had to change the name of the module to match what i had to this
<modules>
<Damian_CmsUpdate> <!-- Name had to change to match folder name -->
<version>0.1</version>
</Damian_CmsUpdate>
</modules>
and then had to update the setup in the config.xml to this
<! -.....- >
<setup>
<module>Damian_CmsUpdate</module>
<class>Damian_CmsUpdate_Model_Resource_Mysql4_Setup</class>
</setup>
<! -......- >

WCF stream json request method not found

facing issues when send attach image to wcf server using json request to WCF. error is method not allowed.
Here is Interface
[ServiceContract]
public interface IFileUploadServ
{
[OperationContract(Name = "UploadFile")]
[WebInvoke(Method = "POST", UriTemplate = "/UploadFile", ResponseFormat = WebMessageFormat.Json)]
string UploadFile(Stream stream);
}
Here is implementation
public string UploadFile(Stream stream)
{
// Code will be here to read stream and upload to DB
return "Done";
}
Here is web config
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="MyWcfRestService.WebHttp" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
transferMode="Streamed"
sendTimeout="00:05:00">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MyWcfRestService.FileUploadServBehavior" name="ImageUpload.FileUploadServ">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="MyWcfRestService.WebHttp" contract="ImageUpload.IFileUploadServ">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://10.100.103.41/DCASTestService/FileUploadServ.svc"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyWcfRestService.FileUploadServBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
</webScriptEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
Here is json call
json call to wcf service hosted in server
function UploadFile() {
fileData = document.getElementById("fileUpload").files[0];
var data = new FormData();
$.ajax({
url: 'http://10.100.103.41/DCASTestService/FileUploadServ.svc/UploadFile',
type: 'POST',
data : fileData,
cache: false,
dataType: 'json',
processData: false, // Don't process the files
contentType: "application/octet-stream", // Set content type to false as jQuery will tell the server its a query string request
success: function (data) {
alert('successful..' + data.UploadFileResult);
},
error: function (data) {
alert('Some error Occurred!' + data.UploadFileResult);
}
});
}