How can I increase the maximum file name size of attachments in Prestashop 1.7 - prestashop

On Prestashop 1.7, how can I increase the maximum file name size of attachments?
While naming attachment files in the Back Office, I encounter the following error message.
How can I go around this problem in Prestashop 1.7? I looked up online and found some solutions for Prestashop 1.5 or 1.6, but not for 1.7.
Here are some links that I followed:
https://www.prestashop.com/forums/topic/63332-bug-the-field-mime-is-too-long-32-chars-max/?tab=comments#comment-1189602
https://www.prestashop.com/forums/topic/81129-solvedhow-to-change-the-length-of-the-file-name-of-the-attachement/?tab=comments#comment-1197114
Following the above links, I have tried:
In the DB, changed the 'name' column's type in the 'ps_attachment_lang' table to 'varchar(128)'.
In Attachment.php (/classes/Attachment.php), made sure the size is 128.
'name' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128],
In AdminProductsController.php (/controllers/admin/AdminProductsController.php), changed a part of function ajaxProcessAddAttachment(), from
if (!Validate::isGenericName($name)) {
$_FILES['attachment_file']['error'][] = $this->trans('Invalid name for %s language', [$language['name']], 'Admin.Notifications.Error');
} elseif (Tools::strlen($name) > 32) {
$_FILES['attachment_file']['error'][] = $this->trans('The name for %1s language is too long (%2d chars max).', [$language['name'], 32], 'Admin.Notifications.Error');
}
to
if (!Validate::isGenericName($name)) {
$_FILES['attachment_file']['error'][] = $this->trans('Invalid name for %s language', [$language['name']], 'Admin.Notifications.Error');
} elseif (Tools::strlen($name) > 64) {
$_FILES['attachment_file']['error'][] = $this->trans('The name for %1s language is too long (%2d chars max).', [$language['name'], 64], 'Admin.Notifications.Error');
}
But unfortunately, none of them worked.
Thanks in advance.

This is my own question but I found one solution.
In the AttachmentConstraint.php (in /src/Core/Domain/Attachment/Configuration/AttachmentConstraint.php), find the line
const MAX_NAME_LENGTH = 32;
and change it to whatever number that is lower than your database table can hold:
//const MAX_NAME_LENGTH = 32;
const MAX_NAME_LENGTH = 128; // this number needs to be lower than `name` column in `ps_attachment_lang` table
This should do the trick, but this solution requires changes in the core file. If there's anyone who knows a way we can achieve this without modifying the core files, please share that.

Related

getProduct()->getTag() return null, when it should return tags associated to the Product

In my project, we have products that has tag called serviceItem. Those item with that tag when ordered should be separated by the quantity into individuals order.
It issue is that getTags() returns null, and getTagIds gets "Call to a member function getTagIds() on null" when it gets to the next loop.
Is there a reason for why getTags() returns null?
private function transformOrderLines(OrderEntity $order): array
{
/**
* TODO: If we need to send advanced prices,
* the price value of the the lines array should be changed to caldulate the advanced price,
* with the built in quantity calculator
*/
$lines = [];
foreach ($order->getLineItems() as $orderLine) {
$hasDsmServiceItemTag = $orderLine->getProduct()->getTags();
$lines[] = [
'name' => $orderLine->getLabel(),
'sku' => substr($orderLine->getProduct()->getProductNumber(), 0, 19),
'price' => (string) ($orderLine->getProduct()->getPrice()->first()->getNet()
* $order->getCurrencyFactor()), //gets original price, calculates factor
'quantity' => (string) $orderLine->getQuantity()
];
}
$shipping = $this->transformShipping($order);
if ($shipping) {
$lines = array_merge($lines, $shipping);
}
return $lines;
}`
I also tried $orderLine->getProduct()->getTags()->getName() it also return "Call to a member function getTags() on null"
The problem is wherever the $order is fetched from the DB the orderLineItem.product.tag association is not included in the criteria.
For performance reasons shopware does not lazily load all association when you access them on entities, but you have to exactly define which associations should be included when you fetch the entities from the database.
For the full explanation take a look at the docs.

Rose::DB masking in query statements

I'm seeking some help on my Rose::DB issue as described below.
I have an account object, and this has an integer "accounttype" field. In this example I will use the following accounttype constants:
ACCOUNT_TYPE_SPECIAL_MASK = 0x10;
ACCOUNT_TYPE_SPECIAL_1 = 0x10;
ACCOUNT_TYPE_SPECIAL_2 = 0x11;
ACCOUNT_TYPE_NORMAL_MASK = 0x20;
ACCOUNT_TYPE_NORMAL_1 = 0x20;
ACCOUNT_TYPE_NORMAL_2 = 0x21;
At present, when I want accounts of a given type, I'd list them all and do something like this:
my $iter = Test::Account::Manager->get_accounts_iterator(
db => $db,
query =>
[
'accounttype' => [ ACCOUNT_TYPE_SPECIAL_1, ACCOUNT_TYPE_SPECIAL_2 ],
]
);
However, I'd like to be able to query for the accounts using the appropriate mask, rather than specify all possible types.
I'd like to be able to say:
my $iter = Test::Account::Manager->get_accounts_iterator(
db => $db,
query =>
[
'accounttype' => 'accounttype & ACCOUNT_TYPE_SPECIAL_MASK'
]
);
However, I haven't spotted any way to do this. Any help or recommendations most welcome.
Thanks!
Let's say your SQL server understands the following:
(accounttype & 16) <> 0
This would then suggest that you could use the following:
[ \'(accounttype & ?) <> 0' => ACCOUNT_TYPE_SPECIAL_MASK ]
Under the circumstances, you could inline the constant.
\sprintf('(accounttype & %d) <> 0', ACCOUNT_TYPE_SPECIAL_MASK)
I don't know if these two versions result in different SQL, and I don't know which is faster if so.

PayPal Api Patch on Itemlist doesn't work

I want to add an item to my transaction.
$json = '
[
{
"name": "Voucher",
"description":"Voucher",
"price":"50.00",
"currency":"EUR",
"quantity":"1"
}
]';
$patchAddItem = new \PayPal\Api\Patch();
$patchAddItem->setOp('add')
->setPath('/transactions/0/item_list/items')
->setValue(json_decode($json));
$patchReplace = new \PayPal\Api\Patch();
$patchReplace->setOp('replace')
->setPath('/transactions/0/amount')
->setValue(json_decode('{
"total": "159.00",
"currency": "EUR",
}'));
$patchRequest = new \PayPal\Api\PatchRequest();
$patchRequest->setPatches(array($patchAddItem, $patchReplace));
try {
$this->payment->update($patchRequest, $this->apiContext);
} catch (PayPal\Exception\PayPalConnectionExceptio $ex) {
echo '<pre>';print_r(json_decode($ex->getData()));exit;
}
But I get following Error
Eception: Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAY... in PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php on line 154
PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php on line 73: PayPal\Core\PayPalHttpConnection->execute("[{"op":"add","path":"/transactions/0/item_list/ite"... )
PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php on line 102: PayPal\Transport\PayPalRestCall->execute(array[1],"/v1/payments/payment/PAY-1S151200BX2478240LEAG3CI","PATCH","[{"op":"add","path":"/transactions/0/item_list/ite"... ,null)
PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Api/Payment.php on line 615: PayPal\Common\PayPalResourceModel::executeCall("/v1/payments/payment/PAY-1S151200BX2478240LEAG3CI","PATCH","[{"op":"add","path":"/transactions/0/item_list/ite"... ,null,object,null)
At this moment I didn't execute the payment object. Do I have to edit the total attribut from amount too? Well, I tried this too, with same issue...
Even if you are sending only one item to PayPal you still have to set them as an item list with setItemList().
That array should be visible if you json_decode in your payment array:
[item_list] => Array
(
[items] => Array
(
[0] => Array
(
[name] => Ground Coffee 40 oz
[sku] => 123123
[price] => 52.80
[currency] => USD
[quantity] => 1
)
)
I had not run a patch for an item yet. I attempted to send an 'add' similar to your code and tried changing the path to '/transactions/0/item_list/items/1' using the next number in the items array. But could not get an add to work.
The only way I could modify the item_list was to do a complete 'replace' of the item_list, so in a running shopping cart would have to include all the items being purchased, not just the new item.
To do this I prefer to use the functions from the PayPal sdk vs building the json arrays. Their examples of how to create and execute a payment are fairly good and use the SDK functions. http://paypal.github.io/PayPal-PHP-SDK/sample/
However the example on updating a payments builds the json arrays outright.
Below is a testing function to modify the item_list using the Paypay PHP SDK Class Functions. I hard coded the Subtotal and Total to match the values coming form the shopping cart plus the increase from the new item. The item_list is also hard coded using PP's example data. Otherwise item's arrays would be built off of a user's shopping cart items. The type is set to 'replace'.
So, yes. Subtotals and Totals need to be updated to match as well, else the PP call will fail.
function updatePayPalPayment ($type, $createdPayment, $total, $subtotal, $shipping, $currency) {
$subtotal = '54.80';
$total = '71.73';
$details = new Details();
$details->setShipping($shipping)
->setSubtotal($subtotal);
$amount = new Amount();
$amount->setCurrency($currency)
->setTotal($total)
->setDetails($details);
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setSku("123123") // Similar to `item_number` in Classic API
->setPrice(52.80);
$item2 = new Item();
$item2->setName('Granola bars')
->setCurrency('USD')
->setQuantity(1)
->setSku("321321") // Similar to `item_number` in Classic API
->setPrice(2.0);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
$patchItem = new Patch();
$patchItem->setOp($type)
->setPath('/transactions/0/item_list')
->setValue($itemList);
$patchAmount = new Patch();
$patchAmount->setOp($type)
->setPath('/transactions/0/amount')
->setValue($amount);
$patchRequest = new PatchRequest();
$patchRequest->setPatches(array($patchAmount, $patchItem));
$update = $createdPayment->update($patchRequest, getApiContext());
return $update;
}
I also have found it very helpful to set the apiContext for logging to DEBUG and output to a file in development for much better error messages.
'log.LogEnabled' => true,
'log.FileName' => '_PayPal.log',
'log.LogLevel' => 'DEBUG',
Hope that helps.

Reflection Added to db but file does not exit

File is relative to /file/repository/AutoSalon/hasi/BB_Light_House_8.png
ipFileUrl(ipReflection('AutoSalon/'.$user['username'].'/'.$value['photo1'],$opti‌​ons,'thumb_'.$value['photo1'],true));
(36, options ,fprit, 'AutoSalon/hasi/BB_Light_House_8.png', '2016/02/03/thumb_BB_Light_House_8.png', 1454520313);
BUT there is no File in /file/2016/02/03/thumb_BB_Light_House_8.png
GET http://kukur.dev/file/2016/02/03/thumb_BB_Light_House_8_1.png 404 (Not Found)
Here is LOG FILE
{"errorTrace":"#0 /Users/flakerimi/Sites/ImpressPages/Ip/Internal/Repository/ReflectionModel.php(60): Ip\Internal\Repository\ReflectionModel->createReflectionRecord('AutoSalon/hasi/', Array, NULL)\n#1 /Users/flakerimi/Sites/ImpressPages/Ip/Internal/Repository/ReflectionService.php(84): Ip\Internal\Repository\ReflectionModel->getReflection('AutoSalon/hasi/', Array, NULL, true)\n#2 /Users/flakerimi/Sites/ImpressPages/Ip/Functions.php(957): Ip\Internal\Repository\ReflectionService->getReflection('AutoSalon/hasi/', Array, NULL, true)\n#3 /Users/flakerimi/Sites/ImpressPages/Plugin/AutoSalon/view/user/list.php(25): ipReflection('AutoSalon/hasi/', Array)\n#4 /Users/flakerimi/Sites/ImpressPages/Ip/View.php(111): require('/Users/flakerim...')\n#5 /Users/flakerimi/Sites/ImpressPages/Ip/Application.php(352): Ip\View->render()\n#6 /Users/flakerimi/Sites/ImpressPages/Ip/Application.php(442): Ip\Application->handleRequest(Object(Ip\Request), Array, false)\n#7 /Users/flakerimi/Sites/ImpressPages/Ip/script/run.php(8): Ip\Application->run()\n#8 /Users/flakerimi/Sites/ImpressPages/index.php(14): require_once('/Users/flakerim...')\n#9 {main}"}
Just for Archive purpose:
Problem was with $options,
$options = array('type' => 'center', 'widht' => 400, 'height'=>200, 'forced' => true);
There is a typo at Width (widht) and thats why. Maybe some better check on that ?

display product features in groups

i'm new to prestashop i want to display my product features in groups. like shown below
OUTPUT
light source :
color :
MECHANICAL
Tempreture :
weight :
height :
ELECTRICAL
input voltage :
power consumption :
here output, mechanical, electricals are groups. light source, color, weight's are features of that groups.
please help me for this problem..
At some point or another you will have to modify Product page template (I assume you want to display categorized features in product page).
You could create a module for categorozing features, but then you'd still have to modify product template;
The most straightforward way would be to hard-code the categories into product.tpl:
{if $feature.id == 1}
...
{elseif $feature.id == 2}
...
{/if}
However, I don't recommend this. THe better way would be to create a simple module in which you would prepare categorized feature for your product page:
public function hookDisplayFooterProduct {
// pick ane product page hook, not necessarilly displayFooterProduct;
$categorized_features = array(
'electrical' => array(),
'mechanical' => array(),
'other' => array(),
);
foreach($product->features as $f)
{
switch ($f->name)
{
case 'inpu voltage':
$categorized_features['electrical'][] = $f;
break;
....
default:
$categorized_features['other'][] = $f;
}
}
}
$this->context->smarty->assign(array(
'categorized_features' => $categorized_features,
));
Then modify product.tpl
{foreach $$categorized_features as $cf}
{$f->name}: {$f->value}
{/foreach}
Bear in mind that this example just displays the idea.