Magento 2 add custom column into quote table - magento2

I'm trying to add another column into quote table for Magento 2.
App/Code/[CompanyName]/[Module]/Setup/UpgradeSchema.php
Here's my code:
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Quote\Setup\QuoteSetupFactory;
use Magento\Framework\DB\Ddl\Table;
use Magento\Quote\Setup\QuoteSetup;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
$connection = $installer->getConnection();
$connection->addColumn($installer->getTable('quote'), 'can_ship_partially', [
'type' => Table::TYPE_SMALLINT,
'nullable' => true,
'comment' => 'Custom can ship partial'
]);
$installer->endSetup();
}
}//End of class
But when I ran sudo php bin/magento setup:upgrade the column can_ship_partially never show up in the quote table. Could someone tell me what did I do wrong please. Thanks

your code is working well, so I think you Schema-Script is never be called.
Schema-Scripts are called when modules setup version has been increased.
Check your database, table "module_module" and search for your module entry. Compare the version value with your setup_version value in your module.xml. if the value is the same, try to increase setup_version in your module.xml.

Related

backpack for laravel: how to add a custom action / operation?

I need to add and operation to handle downloading of a file.
How can i create route, and add setupDownloadOperation in the right way?
Or must I simply do 'laravel-way' manually adding a route?
Actually we did this
First - Create a setupDownloadRoutes
Actually this is called automatically ad boot
protected function setupDownloadRoutes($segment, $routeName, $controller)
{
Route::get($segment. '/{id}/download', [
'as' => $routeName . '.download',
'uses' => $controller . '#download',
'operation' => 'download',
]);
}
Create the setupDownloadOperation function
It's automatically launched if found. If you have nothing to do here you can avoid to create it.
protected function setupDownloadOperation()
{
...do things here...
}
Create the download function.
This is the classic controller action of Laravel
protected function download()
{
... do thing as usually in a normal action ...
}
I do not find these procedure documented actually
The docs here cover exactly what you need. Just replace “moderate” with “download” in the naming - https://backpackforlaravel.com/docs/4.1/crud-operations

TYPO3 Extension: 'Unknown column in field list' error

Basically: Every time I add a new class/model with the extension_builder and then want to create a record of that class I get the following error message:
2: SQL error: 'Unknown column 'edited' in 'field list''
(tx_icingaconfgen_domain_model_checkperiod:NEW5a27f9da8a41d636846075)
The interesting thing is: "edited" is NOT a property of that class, but the property of other classes in that extension. I've searched through the TCA of the class that throws the error and also the MySql table itself, but the field "edited" is indeed not part of that class. What's going on here?
Edit: What I find interesting is the fact that when I add a column "edited" to MySql table manually, the record can be created. But in no way I'm using this property in my Model. Why does it require a MySql column of that name then?
Without seeing the code I can only guess whats going on. Surely the field is requiered when a record is persisted. So it is possible that you referenced it in your TCA. If not in the columns maybe in the ctrl section:
'ctrl' => [
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
...
],
These fields are updated automatically if a recods is changed or created. There are more of those fields. So check your ctrl section.
It is also possible that you map another property (possibly even of another class) to that database field in your TypoScript like this:
plugin.tx_myextension {
persistence {
classes {
MyVendor\MyExtension\Domain\Model\Person {
mapping {
tableName = tt_address
recordType = \MyVendor\MyExtension\Domain\Model\Person
columns {
birthday.mapOnProperty = dateOfBirth
}
}
}
}
}
}
Example taken from here.
As it turned out the culprit was actually this line of code in the ext_localconf.php:
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['extkey'] = 'Cjk\\Icingaconfgen\\Hook\\EvalHook';
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['extkey'] = 'Cjk\\Icingaconfgen\\Hook\\EvalHook';
It's a hook that I've implemented into my extension that just marks if a record has been edited in the BE or not. I actually use this Hook that whenever a record is edited changes the propety edited from 0 to 1. This is intended of course, but the class checkperiod doesn't have the property 'edited'. But since the hook for the Datamapper works with every record that is changed or created it also tries to change 'edited' in classes that don't have this property. A simple if condition in the Hook itself, if the key 'edited' of the $fieldArray is NULL solved my problem.
class EvalHook {
function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, &$pObj) {
if($status == "update" && $table != 'tx_icingaconfgen_domain_model_checkperiod'){
$fieldArray[edited] = 1;
}
elseif($status != "update" && $table != 'tx_icingaconfgen_domain_model_checkperiod){
$fieldArray[edited] = 0;
}
}
}

SugarCRM v6.5 How to get the field from another module and display it into a different module?

I know about the relationship but they only get the primary field, not the other fields. For example, I have two modules, module 1 holds the personal information of the user while module 2 let us say holds the person's activities. in module 2 I would like to display the gender base on his information from module 1.
How can I proceed with this?
Please follow below steps to achieve this:
Note: Make sure the Module-1 and Module-2 has one of the relationship 1-M or M-M
Step-1: Create new field in Module-2 to store/display the gender
values
Step-2: Create new file in Module-2
location(custom/modules/Module2/views/view.detail.php)
<?php
require_once('include/MVC/View/views/view.detail.php');
class Module2ViewDetail extends ViewDetail {
function Module2ViewDetail() {
parent::ViewDetail();
}
function display() {
$recordId = $this->bean->id;
global $db;
if($recordId){
/* write a query to fetch gender($gender) from module */
}
$this->dv->process();
$this->ss->assign('GENDER',$gender);
echo $this->dv->display();
}
}
?>
Step 3: \custom\modules\Module2\metadata\detailviewdefs.php
Add the customCode in the gender field which you have created in Module2 like below. (Please note: Give the name of field similar to you custom field name):
1 =>
array (
0 =>
array (
'name' => 'gender_c',
'label' => 'LBL_GENDER',
'customCode' => '{$GENDER}',
),
1 => '',
),
Hope this will help you. Thanks!

Fuelphp input and session issue in model

I ran into a problem what i cant really solve (i am a begginer with fuelphp).
So when i place input in my model i get this error
ErrorException [ Error ]: Class 'Model\Input' not found
when i try with session its the same thing
ErrorException [ Error ]: Class 'Model\Session' not found
And when i try to hardcode a value in it its not inserting, debuged the query no errors. it shows the value is posted (when passing hard code value) but not inserts it in the database.
my code
model
namespace Model;
use DB;
class Event extends \Model {
static function send_event()
{
$query = DB::insert('events');
$query->set(array(
'user_id' => Session::get('sentry_user'),
'event_name' => Input::post('event_name'),
'event_desc' => Input::post('event_desc'),
'event_start' => Input::post('event_start'),
'event_end' => Input::post('event_end'),
));
}
}
controller
function action_send_data()
{
$response = Response::forge();
$val = Validation::forge('events');
$val->add_field('event_name', 'Esemény neve', 'required');
$val->add_field('event_desc', 'Esemény leírás', 'required');
$val->add_field('event_start', 'Esemény kezdődik', 'required');
$val->add_field('event_end', 'Esemény kejár', 'required');
Event::send_event();
$response->body(json_encode(array(
'status' => 'ok',
)));
return $response;
}
could please someone give me a hint what i am doing wrong?
thank you
P.S: in the controller i removed the validation for query debuging
When you declare a namespace at the top of a file as you have done with
namespace Model;
This declares the namespace for all classes called where the namespace is not explicitly defined. For example, your call to Session is actually looking in Model\Session when it actually exists in \Fuel\Core\Session
There are two ways around this. You've demonstrated an example yourself in your question with a call to the use language construct.
use DB;
This causes PHP to search for classes in this namespace as well as the one which is already being used (Model in this case).
The other way you can do it is by calling the class with the explicit namespace. For example
\Fuel\Core\Session::get();
Fuel also aliases all core classes to the root namespace for convenience. What this means is you can also directly call classes in \Fuel\Core just using \. For example
\Session::get();

DBIx::Class Wrapping/overloading a column accessor

Using DBIx::Class I am trying to manipulate the data of a column whenever it is being updated or retrieved. For instance, before it goes into the database I would like to encrypt it, and whenever it is being accessed I would like to decrypt it. I am following this example in the DBIx::Class::Manual::Cookbook, however I can't seem to get it to work. I have placed the following in my User schema. For testing I am just using the name column, I know it doesn't make sense:
__PACKAGE__->add_columns("name" => { accessor => '_name' });
sub name {
my $self = shift;
# If there is an update to the column, we'll let the original accessor
# deal with it.
if(#_) {
return $self->_name('test 1');
}
# Fetch the column value.
my $name = $self->_name;
$name = 'test 2';
return $name;
}
I can't see what I'm doing any different than what the cookbook says. Can't anyone help me understand what I'm doing wrong? Thanks!
DBIx::Class has a component for that called FilterColumn.
There are various modules on CPAN using that component like DBIx::Class::EncodedColumn and PassphraseColumn.
If you tell us what you use case is we might give you more/better suggestions.