EF query cast from TakeResultOperator to GroupResultOperator error - entity-framework

_dailySaleReportRepository.GetAll().Where(filter).GroupBy(p => p.StoreId).PageBy(input).Select(p => new DailySaleReportSearchResult()
{
StoreId = p.Key,
StoreName = p.FirstOrDefault().StoreName,
ParkName = p.FirstOrDefault().ParkName,
AliMoney = p.Sum(g => g.AliMoney),
CashMoney = p.Sum(g => g.CashMoney),
CouponMoney = p.Sum(g => g.CouponMoney),
DiscountAmount = p.Sum(g => g.DiscountAmount),
FtMoney = p.Sum(g => g.FtMoney),
MutonePayMoney = p.Sum(g => g.MutonePayMoney),
MutoneTradeMoney = p.Sum(g => g.MutoneTradeMoney),
OrederNumbers = p.Sum(g => g.OrederNumbers),
RefundAmount = p.Sum(g => g.RefundAmount),
RefundNumbers = p.Sum(g => g.RefundNumbers),
TotalAmount = p.Sum(g => g.TotalAmount),
TradeAmount = p.Sum(g => g.TradeAmount),
WxMoney = p.Sum(g => g.WxMoney),
}).ToList()
when I use this code to get a sum value I got an error
"Unable to cast object of type 'Remotion.Linq.Clauses.ResultOperators.TakeResultOperator' to type 'Remotion.Linq.Clauses.ResultOperators.GroupResultOperator'."
but when I first cast group to dictionary then use select ,it will work well.

Related

How to use filter result with list integer in IQueryable

My program contains several tables. Some of these tables are as follows:
Country table - Product table - ProductCountry (junction table).
When filters are applied on the page of the store (example.com/shop), I want to apply the filter of the selected countries to the result, which goes through various stages (the ID of these countries is a list of integer)
I wrote several ways, all of which have errors.
Thank you for your help
IQueryable<ProductLocalization> result = _context.ProductLocalizations
.Include(c => c.Languages)
.Include(c => c.ProductPropertyLocalizations)
.Include(c => c.Product)
.Include(c => c.Product.UserProducts)
.Include(c => c.Product.Brand)
.Include(c => c.Product.Category)
.Include(c => c.Product.Category.CategoryPropertyLocalizations)
.Where(c => c.LanguageId == languageId);
if (countryId.Count != 0)
{
result = result.Where(c => countryId.Contains(c.Product.CountryProducts.Select(b => b.CountryId));
result = result.Where(c => c.Product.CountryProducts.Any(b => b.CountryId == countryId));
result = result.Where(c => countryId.Any(b => b == c.Product.CountryProducts[0].CountryId)); //for example
result = result.Where(c => c.Product.CountryProducts.Select(c => countryId.Any(c.CountryId)));
result = result.Where(c => c.Product.CountryProducts.FindAll(b => b.CountryId == countryId));
result = result.Where(c => c.Product.CountryProducts.Select(c => c.CountryId).Contains(countryId);
result = result.Where(c => countryId.Any(b => b == c.Product.CountryProducts.Select(a=>a.CountryId)));
}
Try the following filter:
result = result.Where(c =>
c.Product.CountryProducts.Any(b => countryId.Contains(b.CountryId))
);

yii2fullcalendar week view

I find this anomaly in week view
In my month view is all perfect
But in week view no
I put this code in the index.php
<?= \yii2fullcalendar\yii2fullcalendar::widget(array(
'options' => ['lang' => 'it',
'class' => 'fullcalendar',
],
'clientOptions' => [
'selectable' => true,
'selectHelper' => true,
'droppable' => true,
'editable' => true,
'slotEventOverlap'=>True,
'googleCalendar' => true,
// 'drop' => new JsExpression($JSDropEvent),
'select' => new JsExpression($JSCode),
'eventClick' => new JsExpression($JSEventClick),
'defaultDate' => date('Y-m-d')
],
'events'=> Url::to(['/agenda/jsoncalendar']),
// $events,
) );?>
and this into controller
public function actionJsoncalendar($start=NULL,$end=NULL,$_=NULL){
// \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$times = Agenda::find()->all();
$events = array();
foreach ($times AS $time){
//Testing
$Event = new \yii2fullcalendar\models\Event();
$Event->id = $time->id;
$Event->title = $time->elemento;
$Event->start = date('Y-m-d\TH:i:s\Z',strtotime($time->dadata));
$Event->end = date('Y-m-d\TH:i:s\Z',strtotime($time->adata));
$Event->overlap=true;
$Event->startEditable = true;
$Event->durationEditable = true;
$el = trim($time->elemento);
switch ($el) {
case 'ELE1':
$Event->color = 'green';
break;
case 'ELE2':
$Event->color = 'red';
break;
case 'ELE3':
$Event->color = 'black';
break;
case 'ELE4':
$Event->color = 'purple';
break;
case 'ELE5':
$Event->color = 'brown';
break;
case 'ELE6':
$Event->color = 'blue';
break;
}
$events[] = $Event;
}
\Yii::warning($events);
return json_encode($events);
}
This is the data structure, where dadata is the start data and adata is end data
and the data
But I don't think or better I dot know if it guilty...
what can be?
tks a lot!
#fidels80

PrestaShop 1.6 add order product to custom email template

I copy order_conf.tpl and order_conf.txt file from mail folder and rename it. Now add override to classes/order/OrderHistory.php
I change function sendemail() to:
public function sendEmail($order, $template_vars = false)
{
$result = Db::getInstance()->getRow('
SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, os.`pdf_invoice`, os.`pdf_delivery`
FROM `'._DB_PREFIX_.'order_history` oh
LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1');
if (isset($result['template']) && Validate::isEmail($result['email'])) {
ShopUrl::cacheMainDomainForShop($order->id_shop);
$topic = $result['osname'];
/*----------------------
-START OF INSERTED CODE-
----------------------*/
/* GET THE PRODUCTS */
$order_details = $order->getProducts();
$product_var_tpl_list = array();
foreach ($order_details as $id => &$order_detail) {
$product_var_tpl = array(
'reference' => $order_detail['product_reference'],
'name' => $order_detail['product_name'].(isset($order_detail['product_attributes']) ? ' - '.$order_detail['product_attributes'] : ''),
'unit_price' => Tools::displayPrice($order_detail['unit_price_tax_incl'], $this->context->currency, false),
'price' => Tools::displayPrice($order_detail['total_price_tax_incl'], $this->context->currency, false),
'quantity' => $order_detail['product_quantity'],
'customization' => $order_detail['customizedDatas']
);
$product_var_tpl_list[] = $product_var_tpl;
} // end foreach ($order_detail)
$product_list_txt = '';
$product_list_html = '';
if (count($product_var_tpl_list) > 0) {
$product_list_txt = $this->getEmailTemplateContent('order_conf_product_list.txt', Mail::TYPE_TEXT, $product_var_tpl_list);
$product_list_html = $this->getEmailTemplateContent('order_conf_product_list.tpl', Mail::TYPE_HTML, $product_var_tpl_list);
}
/* GET THE DISCOUNTS */
$cart_rules = $order->getCartRules();
foreach ($cart_rules as $id => &$cart_rule) {
$cart_rules_list[] = array(
'voucher_name' => $cart_rule['name'],
'voucher_reduction' => ($cart_rule['value'] != 0.00 ? '-' : '').Tools::displayPrice($cart_rule['value'], $this->context->currency, false)
);
}
$cart_rules_list_txt = '';
$cart_rules_list_html = '';
if (count($cart_rules_list) > 0) {
$cart_rules_list_txt = $this->getEmailTemplateContent('order_conf_cart_rules.txt', Mail::TYPE_TEXT, $cart_rules_list);
$cart_rules_list_html = $this->getEmailTemplateContent('order_conf_cart_rules.tpl', Mail::TYPE_HTML, $cart_rules_list);
}
/* GET ORDER DETAILS, delivery, invoice, amount... etc */
$invoice_address = new Address((int)$order->id_address_invoice);
$invoiceAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true);
$deliveryAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true);
$country = new Country((int)$invoice_address->id_country);
$delivery_address = null;
$formatted_delivery_address = '';
if (isset($order->id_address_delivery) && $order->id_address_delivery) {
$delivery_address = new Address((int)$order->id_address_delivery);
}
$carrier = new Carrier((int)($order->id_carrier), $order->id_lang);
/* ATTACH INFORMATION TO SMARTY VARIABLE*/
$data = array(
'{lastname}' => $result['lastname'],
'{firstname}' => $result['firstname'],
'{id_order}' => (int)$this->id_order,
'{delivery_block_txt}' => AddressFormat::generateAddress($delivery_address, $deliveryAddressPatternRules, ', ', ' '),
'{invoice_block_txt}' => AddressFormat::generateAddress($invoice_address, $invoiceAddressPatternRules, ', ', ' '),
'{delivery_block_html}' => AddressFormat::generateAddress($delivery_address, $deliveryAddressPatternRules, '<br />',' ', array(
'firstname' => '<span style="font-weight:bold;">%s</span>',
'lastname' => '<span style="font-weight:bold;">%s</span>'
)),
'{invoice_block_html}' => AddressFormat::generateAddress($invoice_address, $invoiceAddressPatternRules, '<br />',' ', array(
'firstname' => '<span style="font-weight:bold;">%s</span>',
'lastname' => '<span style="font-weight:bold;">%s</span>'
)),
'{delivery_company}' => $delivery_address->company,
'{delivery_firstname}' => $delivery_address->firstname,
'{delivery_lastname}' => $delivery_address->lastname,
'{delivery_address1}' => $delivery_address->address1,
'{delivery_address2}' => $delivery_address->address2,
'{delivery_city}' => $delivery_address->city,
'{delivery_postal_code}' => $delivery_address->postcode,
'{delivery_country}' => $delivery_address->country,
'{delivery_state}' => $delivery_address->id_state ? $delivery_state->name : '',
'{delivery_phone}' => ($delivery_address->phone) ? $delivery_address->phone : $delivery_address->phone_mobile,
'{delivery_other}' => $delivery_address->other,
'{invoice_company}' => $invoice_address->company,
'{invoice_vat_number}' => $invoice_address->vat_number,
'{invoice_firstname}' => $invoice_address->firstname,
'{invoice_lastname}' => $invoice_address->lastname,
'{invoice_address2}' => $invoice_address->address2,
'{invoice_address1}' => $invoice_address->address1,
'{invoice_city}' => $invoice_address->city,
'{invoice_postal_code}' => $invoice_address->postcode,
'{invoice_country}' => $invoice_address->country,
'{invoice_state}' => $invoice_address->id_state ? $invoice_state->name : '',
'{invoice_phone}' => ($invoice_address->phone) ? $invoice_address->phone : $invoice_address->phone_mobile,
'{invoice_other}' => $invoice_address->other,
'{order_name}' => $order->getUniqReference(),
'{date}' => Tools::displayDate(date('Y-m-d H:i:s'), null, 1),
'{carrier}' => (!isset($carrier->name)) ? Tools::displayError('No carrier') : $carrier->name,
'{payment}' => Tools::substr($order->payment, 0, 32),
'{products}' => $product_list_html,
'{products_txt}' => $product_list_txt,
'{discounts}' => $cart_rules_list_html,
'{discounts_txt}' => $cart_rules_list_txt,
'{total_paid}' => Tools::displayPrice($order->total_paid, $this->context->currency, false),
'{total_products}' => Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $order->total_products : $order->total_products_wt, $this->context->currency, false),
'{total_discounts}' => Tools::displayPrice($order->total_discounts, $this->context->currency, false),
'{total_shipping}' => Tools::displayPrice($order->total_shipping, $this->context->currency, false),
'{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $this->context->currency, false),
'{total_tax_paid}' => Tools::displayPrice(($order->total_products_wt - $order->total_products) + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $this->context->currency, false)
);
/*---------------------
!-END OF INSERTED CODE-
---------------------*/
if ($result['module_name']) {
$module = Module::getInstanceByName($result['module_name']);
if (Validate::isLoadedObject($module) && isset($module->extra_mail_vars) && is_array($module->extra_mail_vars)) {
$data = array_merge($data, $module->extra_mail_vars);
}
}
if ($template_vars) {
$data = array_merge($data, $template_vars);
}
$data['{total_paid}'] = Tools::displayPrice((float)$order->total_paid, new Currency((int)$order->id_currency), false);
if (Validate::isLoadedObject($order)) {
// Attach invoice and / or delivery-slip if they exists and status is set to attach them
if (($result['pdf_invoice'] || $result['pdf_delivery'])) {
$context = Context::getContext();
$invoice = $order->getInvoicesCollection();
$file_attachement = array();
if ($result['pdf_invoice'] && (int)Configuration::get('PS_INVOICE') && $order->invoice_number) {
Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $invoice));
$pdf = new PDF($invoice, PDF::TEMPLATE_INVOICE, $context->smarty);
$file_attachement['invoice']['content'] = $pdf->render(false);
$file_attachement['invoice']['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number).'.pdf';
$file_attachement['invoice']['mime'] = 'application/pdf';
}
if ($result['pdf_delivery'] && $order->delivery_number) {
$pdf = new PDF($invoice, PDF::TEMPLATE_DELIVERY_SLIP, $context->smarty);
$file_attachement['delivery']['content'] = $pdf->render(false);
$file_attachement['delivery']['name'] = Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id, null, $order->id_shop).sprintf('%06d', $order->delivery_number).'.pdf';
$file_attachement['delivery']['mime'] = 'application/pdf';
}
} else {
$file_attachement = null;
}
if (!Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname'],
null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int)$order->id_shop)) {
return false;
}
}
ShopUrl::resetMainDomainCache();
}
return true;
}
protected function getEmailTemplateContent($template_name, $mail_type, $var)
{
$email_configuration = Configuration::get('PS_MAIL_TYPE');
if ($email_configuration != $mail_type && $email_configuration != Mail::TYPE_BOTH) {
}
$theme_template_path = _PS_THEME_DIR_.'mails'.DIRECTORY_SEPARATOR.Context::getContext()->language->iso_code.DIRECTORY_SEPARATOR.$template_name;
$default_mail_template_path = _PS_MAIL_DIR_.Context::getContext()->language->iso_code.DIRECTORY_SEPARATOR.$template_name;
if (Tools::file_exists_cache($theme_template_path)) {
$default_mail_template_path = $theme_template_path;
}
if (Tools::file_exists_cache($default_mail_template_path)) {
Context::getContext()->smarty->assign('list', $var);
return Context::getContext()->smarty->fetch($default_mail_template_path);
}
return ' ';
}
In status I create new one status and add option to send my new email to customer, when in order I change status email is send to customer with data but there is missing all product detail from orders.
I don't know how I can correct get this product in my override file.
You don't have the needed templates in your context backoffice language.
Copy files:
/mails/en/order_conf_cart_rules.tpl
/mails/en/order_conf_cart_rules.txt
/mails/en/order_conf_product_list.tpl
/mails/en/order_conf_product_list.txt
To:
/mails/YOUR_BACKOFFICE_USER_LANG_ISO_CODE/order_conf_cart_rules.tpl
/mails/YOUR_BACKOFFICE_USER_LANG_ISO_CODE/order_conf_cart_rules.txt
/mails/YOUR_BACKOFFICE_USER_LANG_ISO_CODE/order_conf_product_list.tpl
/mails/YOUR_BACKOFFICE_USER_LANG_ISO_CODE/order_conf_product_list.txt

plentymarkets add product via soap

im trying to insert product to plentymarkets via soap, but i get this error :
object(stdClass)#14 (2) { ["Success"]=> bool(false) ["ResponseMessages"]=> object(stdClass)#18 (0) { } }
here is my code
$client = new SoapClient($soapUrl);
$aHeader = array(
'UserID' => '12',
'Token' => 'ece85f3bc7a2783b164bf18ed882b6d6' //etcimport
);
$auth_vals = new SoapVar($aHeader, SOAP_ENC_OBJECT);
$ns = "Authentification";
$oSoapHeader = new SoapHeader($ns,'verifyingToken', $auth_vals, false);
$client = new SoapClient($soapUrl);
$client->__setSoapHeaders($oSoapHeader);
$result = $client->AddItemsBase(array(
'ItemNo' => 123,
'ExternalItemID' => 345,
'EAN1' => 4011200296908
));
var_dump($result);

Zend DB query() - how do I perform a database update?

The last line of this code seems to return an object but does not perform the database query. What do I change to get this to actually perform the database update?
$sql = "UPDATE vi_admin_email SET processed_send_list = '?', status = '?' WHERE id = '?'";
$bind = array($addresses,$status,$id);
$res = $this->getAdapter()->query($sql,$bind);
Here is a var dump of the object in $res:
object(Zend_Db_Statement_Pdo)[102]
protected '_fetchMode' => int 2
protected '_stmt' =>
object(PDOStatement)[100]
public 'queryString' => string 'UPDATE vi_admin_email SET processed_send_list = '?', status = '?' WHERE id = '?'' (length=80)
protected '_adapter' =>
object(Zend_Db_Adapter_Pdo_Mysql)[43]
protected '_pdoType' => string 'mysql' (length=5)
protected '_numericDataTypes' =>
array
0 => int 0
1 => int 1
2 => int 2
'INT' => int 0
'INTEGER' => int 0
'MEDIUMINT' => int 0
'SMALLINT' => int 0
'TINYINT' => int 0
'BIGINT' => int 1
'SERIAL' => int 1
'DEC' => int 2
'DECIMAL' => int 2
'DOUBLE' => int 2
'DOUBLE PRECISION' => int 2
'FIXED' => int 2
'FLOAT' => int 2
protected '_defaultStmtClass' => string 'Zend_Db_Statement_Pdo' (length=21)
protected '_config' =>
array
'host' => string 'localhost' (length=9)
'username' => string 'root' (length=4)
'password' => string '' (length=0)
'dbname' => string 'vi' (length=2)
'charset' => null
'persistent' => boolean false
'options' =>
array
...
'driver_options' =>
array
...
protected '_fetchMode' => int 2
protected '_profiler' =>
object(Zend_Db_Profiler)[44]
protected '_queryProfiles' =>
array
...
protected '_enabled' => boolean false
protected '_filterElapsedSecs' => null
protected '_filterTypes' => null
protected '_defaultProfilerClass' => string 'Zend_Db_Profiler' (length=16)
protected '_connection' =>
object(PDO)[85]
protected '_caseFolding' => int 0
protected '_autoQuoteIdentifiers' => boolean true
protected '_allowSerialization' => boolean true
protected '_autoReconnectOnUnserialize' => boolean false
protected '_attribute' =>
array
empty
protected '_bindColumn' =>
array
empty
protected '_bindParam' =>
array
empty
protected '_sqlSplit' =>
array
0 => string 'UPDATE vi_admin_email SET processed_send_list = , status = WHERE id = ' (length=71)
protected '_sqlParam' =>
array
0 => string 'UPDATE vi_admin_email SET processed_send_list = , status = WHERE id = ' (length=71)
protected '_queryId' => null
To update an entry in Zend Framework you do as follow :
$data = array(
'processed_send_list' => $addresses,
'status' => $status
);
$dbAdapter = $this->getAdapter();
$where = $dbApdapter->quoteInto('id = ?', $id);
$this->update($data, $where);
With Zend_Db_Table, the data to be updated is specfied in an associative array as the first parameter. The data provided will be escaped when the query is executed. You also have to include a where statement as a string, like id = 1 as the second parameter. In the above example, the quoteInto is optionnal as you can write the where manually, but the value will not be escaped if you do it manually.
I thought I read "query" but you asked about "update".
So the statement would be:
$res->execute().
Forget what I wrote before.
Try this single line of code,
$res = $this->getAdapter()->query("UPDATE vi_admin_email SET processed_send_list = '$addresses', status = '$status' WHERE id = '$id'");