Hello Guys,
is there any possibility to make the Magento 2 Import-Module uppercase insensitive?
I have attribute-codes like "ColorName" or "BaseColor" and I need them to be working. Right now the data in CSV-File is ignored by Magento for those attributes. The Problem is: I can not change them. There is too much code already written. So i really need magento to recognize uppercase attribute-codes. There is no other solution.
But, is this even possible?
Thanks!
Not sure if this helps, but the attribute code is comverted to lowercase in Magento\CatalogImportExport\Model\Import\Product::retrieveAttributeByCode.
the method looks like this
/**
* Retrieve attribute by code
*
* #param string $attrCode
* #return mixed
*/
public function retrieveAttributeByCode($attrCode)
{
/** #var string $attrCode */
$attrCode = mb_strtolower($attrCode);
if (!isset($this->_attributeCache[$attrCode])) {
$this->_attributeCache[$attrCode] = $this->getResource()->getAttribute($attrCode);
}
return $this->_attributeCache[$attrCode];
}
you can try to override the method and remove the $attrCode = mb_strtolower($attrCode); line or create an around plugin for it.
Related
I have my table information defined via the annotation of the entity. So I would like to change the following column to a TEXT instead of a STRING. So I had this:
/**
* #ORM\Column(type="string", length=255)
*/
private $category;
And I changed it to this:
/**
* #ORM\Column(type="text")
*/
private $category;
I expected it to become a TEXT, so after migrating I checked my database and it says it's a LONGTEXT. I have no idea how this is possible, but before referting my migrations, I would like to know how to make it a TEXT and not a LONGTEXT.
EDIT: I'm looking inside the migration file and I see this:
$this->addSql('ALTER TABLE cabinet CHANGE category category LONGTEXT NOT NULL');
I never typed LONGTEXT so I have no clue where Doctrine is getting that from.
The answer seems to be to give the length of TEXT as well (I thought it was defined as a fixed value), so instead of #ORM\Column(type="text") you should do #ORM\Column(type="text", length=65535). I was able to find this answer because of this other SO question.
If you want to change with migrations you need notate that converting to text will base on the current column length;
$table = $schema->getTable("tablename");
$column = $table->getColumn("columnname");
/** There you need set size of text that you want to use
* To TINYTEXT => length = 0 - 255
* To TEXT => length = 256 - 65535
* To MEDIUMTEXT = 65536 - 16777215
**/
$column->setLength('65535');
$column->setType(Type::getType(Types::TEXT))
It will change current type only if current type is not been Types::TEXT. If your text is tinytext and you need to set it to text, you need first to change type to string, set length and only then set it back to text.
How can I call assertJsonCount using an indexed, nested array?
In my test, the following JSON is returned:
[[{"sku":"P09250"},{"sku":"P03293"}]]
But attempting to use assertJsonCount returns the following error:
$response->assertJsonCount(2);
// Failed asserting that actual size 1 matches expected size 2.
This may or may not be specific to Laravel. Although a Laravel helper is involved, this issue may occur elsewhere.
assertJsonCount utilises the PHPUnit function PHPUnit::assertCount which uses a laravel helper data_get, which has the following signature:
/**
* Get an item from an array or object using "dot" notation.
*
* #param mixed $target
* #param string|array|int $key
* #param mixed $default
* #return mixed
*/
function data_get($target, $key, $default = null)
{
if (is_null($key)) {
return $target;
}
...
We can see that the JSON returned is a nested array, so logically we should pass in a key of 0.
$response->assertJsonCount($expectedProducts->count(), '0');
However this will be ignored as assertCount function checks if a key has been passed using is_null.
To overcome this, we can count all children of 0:
$response->assertJsonCount($expectedProducts->count(), '0.*');
This will produce the desired result.
I have not yet understood where concretely is the problem is...
I have a Doctrine entity with date field:
/**
* #var \DateTime
*
* #ORM\Column(name="day", type="date")
*/
private $day;
Also I have an entity form with date type field:
$builder->add('day', DateType::class, ['widget' => 'single_text'])
And when I try to save the form with value "2016-02-14" I see that it becomes "2016-02-13" (a day earlier) in MySQL and in PHP after saving. When I began looking for logs, I saw that the query parameter value is "2016-02-13 23:00:00".
But I don't understand why it happens this way.
I have the same time and timezone in system (Ubuntu), PHP and MySQL (Europe/Moscow timezone).
I use date type, not datetime, so there should not be time at all.
When I tried to debug it, I saw that code
#vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateType.php
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return ($value !== null)
? $value->format($platform->getDateFormatString()) : null;
}
works correctly. It makes correct format "Y-m-d", but in the symfony log value is with time.
I need an advice about how to find, where my date transforms.
I had a similar problem and used a quick-and-dirty hack. On the setter used for the $day property, just set the time to be midday.
public function setDay(\DateTime $day)
{
$this->day = $day;
$this->day->setTime(12, 0, 0);
return $this;
}
What is the difference between VerificationModeFactory.times() and mockito.times()?
I thought it would be faster to ask rather than go check by myself :) I was lazy and wrong so I did the check by myself and here is the answer. It is the same thing, Mockito.Times() is internally calling the VerificationModeFactory.times()
From Mockito.class
/**
* Allows verifying exact number of invocations. E.g:
* <pre>
* verify(mock, times(2)).someMethod("some arg");
* </pre>
*
* See examples in javadoc for {#link Mockito} class
*
* #param wantedNumberOfInvocations wanted number of invocations
*
* #return verification mode
*/
public static VerificationMode times(int wantedNumberOfInvocations) {
return VerificationModeFactory.times(wantedNumberOfInvocations);
}
I'm working with Symfony 2 and I need to insert some data in a MySQL table. I know how to do it using a form:
$m=new table();
$form=$this->container->get('form.factory')->create(new tableType(),$m);
$request=$this->getRequest();
if($request->getMethod()=='POST')
{
$form->bind($request);
if ($form->isValid())
{
$rm=$this->container->get('doctrine')->getEntityManager();
$rm->persist($m);
$rm->flush();
}
that works but I dont want to use a pre-defined form because I need complex control on my input. I need to generate the value with jQuery.
So how can I proceed to insert the values of my input into my table?
Generally you can pass the whole request to the action as following
use Symfony\Component\HttpFoundation\Request;
// <...>
public function fooAction(Request $request)
{
$foo = $request->query->get('foo', 'default_value_for_foo'); // get the foo param from request query string (GET params)
$bar = $request->query->get('bar', 'default_value_for_bar'); // get the bar param from request POST params
}
Also you might be interested in collection form types which can allow you to generate multiple rows or entities for form (not fixed)
That's actually easier than using forms :D
<?php
// ...
// fetch your params
$m = new table();
$m->setWhatever($request->get('whatever'));
// persist
$em = $this->get('doctrine.orm.entity_manager');
$em->persist($m);
Note:
use camel-case PHP-class names: e.g. Table, NiceTable
$form->bind is deprecated I think, use $form->handleRequest
anyway if you need to validate your input, I recommend using validators and forms anyway. Setting up a model and validate it is quite smart. You don't need to create the view createView() of it of course, but the validation component in Symfony is very mighty :).