I've a system that I need to get a minor tweak made to and hope someone can advise.I've a custom field from a modal called 'cancle_order_reason' that needs to be added to a transactions table when a internal refund is made. Currently the table says just 'internal', but I want it to give the info from the 'cancle_order_reason' field for greater info.
From what I can see the relevant controllers are
packages/catalyst/controllers/dashboard/catalyst/orders.php which is where the modal is.
public function add_refund_order(){
$valt = Loader::helper('validation/token');
if (!$valt->validate('add_refund_order', $this->post('token'))) {
throw new Exception($valt->getErrorMessage());
}
Loader::model('proforms_item','proforms');
$pfo = ProFormsItem::getByID($this->post('orderID'));
$orderID = $this->request('orderID');
$question_set = $pfo->asID;
$setAttribs = AttributeSet::getByID($question_set)->getAttributeKeys();
foreach ($setAttribs as $ak) {
if($ak->getAttributeType()->getAttributeTypeHandle() == 'price_total'){
$value = $pfo->getAttributeValueObject($ak);
$db = Loader::db();
$avID = $value->getAttributeValueID();
$amount = money_format('%(#4n',$this->post('credit_amount'));
$ak->getController()->savePayment($avID,$amount,2);
}
}
$desc = trim($amount . ' ' . $this->request('cancle_order_reason'));
$date = date('Y-m-d');
$u = new User();
$data = array(
'ProformsItemID'=> $this->request('orderID'),
'action'=> 'Refund (Internal)',
'amount'=> $amount,
'description'=> $desc,
'uID'=> $u->uID,
'date' => $date
);
Loader::model('order_history', 'catalyst');
$oh = new OrderHistory();
$oh->addOrderHistoryItem($data);
$this->redirect('/dashboard/catalyst/orders/refund_added_order/?view_order='.$orderID);
}
and then the model controller:
models/attribute/types/price_total/controller.php
public function savePayment($avID=null, $amount, $credit=null, $transID='internal', $type='internal', $status=1){
// $credit == 2 is refund
$this->load();
$db = Loader::db();
if($this->getAttributeValueID()){
$avID = $this->getAttributeValueID();
}
$db->Execute("INSERT INTO atPriceTotalPayments (avID,amount,payment_date,credit,transactionID,type,status) VALUES(?,?,?,?,?,?,?)", [$avID, $amount, date('Y-m-d'), $credit, $transID, $type, $status]);
$this->updatePaidAmount($avID);
}
What is needed is for the details contained in field name ‘cancle_order_reason’ on the modal to be used in place of the ‘internal’ on $transID=‘internal’ on the models/attribute/types/price_total/controller.php. I’ve tested replacing ‘internal’ with some other text, and it updates, so it is the correct one to update.
I’ve tried:
$amount = money_format('%(#4n',$this->post('credit_amount'));
$transID = $this->request('cancle_order_reason');
$ak->getController()->savePayment($avID,$amount,$transID);
And nothing changes.
Changing the other controller so
$transID='internal'
becomes
$transID
results in an error:
Too few arguments to function
PriceTotalAttributeTypeController::savePayment(), 3 passed in
/home/bookinme/web/test.book-in.me/public_html/packages/catalyst/controllers/dashboard/catalyst/orders.php
on line 842 and at least 4 expected.
Related
I use the default codeiginter pagination library. I tried implementing this in a previously created page which shows all vacancies, but since we are getting TOO many on the site, the performance is terrible. This is why I need pagination on this page. Note that this is not the cleanest solution, there is a new track going on which overhauls the entire page and starts from scratch. This is a quick & dirty solution because we need to keep it working on our live environment until the rework is done.
This is the controller code I have:
public function overviewVacancies($city = null)
{
$this->is_logged_in();
// Load Models
$this->load->model('vacancy/vacancies_model');
$this->load->model('perk/interests_model');
$this->load->model('perk/engagement_model');
$this->load->model('user/userSavedVacancies_model');
// Passing Variables
$data['title'] = lang("page_title_activities_overview");
$data['description'] = lang('meta_desc_activities');
$data['class'] = 'vacancy';
$data['engagements'] = $this->engagement_model->getAll();
$data['interests'] = $this->interests_model->getAllInterests();
$data['bread'] = $this->breadcrumbmanager->getDashboardBreadcrumb($this->namemanager->getDashboardBreadName("0"), $this->namemanager->getDashboardBreadName("1"));
$data['tasks'] = $this->interests_model->getAllTasks();
// Set session data
$this->session->set_userdata('previous',"http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
$this->session->set_userdata('previous-title', "1");
$filterdata = array(
'interests' => $this->input->post('interests'),
'skills' => $this->input->post('skills'),
'fulldate' => $this->input->post('daterange'),
'location' => $this->input->post('location'),
'city' => $this->input->post('sublocality_level_1'),
'capital' => $this->input->post('locality')
);
if (!empty($filterdata['interests'])) {
$filterdata['interests'] = rtrim($filterdata['interests'], ";");
$filterdata['interests'] = str_replace(' ', '', $filterdata['interests']);
$filterdata['interests'] = str_replace(';', ',', $filterdata['interests']);
}
if (!empty($filterdata['skills'])) {
$filterdata['skills'] = str_replace(' ', '', $filterdata['skills']);
$filterdata['skills'] = explode(",", $filterdata['skills']);
}
//Manually clear the commune and city variables if the location was empty
if (empty($filterdata['location'])) {
$filterdata['city'] = '';
$filterdata['capital'] = '';
}
if($city == null){
$orgId = $this->organization_model->getOrgIdByName(LOCATION);
}
else{
$orgId = $this->organization_model->getOrgIdByName($city);
$data['bread'] = $this->breadcrumbmanager->getLocalBreadcrumb($this->namemanager->getDashboardBreadName("0"), $city, $data['title'], $data['vacancydetails']);
}
//Set the location to the subdomain automatically (e.g. when the link is clicked) so the activities of that subdomain only show up
if (!empty(LOCATION)) {
$data['title'] = sprintf(lang('page_title_local_activities'), ucwords(LOCATION));
$data['description'] = sprintf(lang('meta_desc_local_activities'), ucwords(LOCATION));
$filterdata['location'] = LOCATION;
$data['bgcolor'] = $this->localSettings_model->getBgColorHexValueForOrgId($orgId->org_id);
}
if (!empty($filterdata['fulldate'])) {
$splitfromandto = explode(" - ", $filterdata['fulldate']);
$filterdata['datefrom'] = $splitfromandto[0];
$filterdata['dateto'] = $splitfromandto[1];
} else {
$filterdata['datefrom'] = null;
$filterdata['dateto'] = null;
}
//Put these variables in the data variable so we can prefill our filters again with the previous values
//This is necessary because we don't use AJAX yet
$data['filterdata'] = $filterdata;
//Pagination : We do it here so we can re-use the filter query to count all our results
$this->load->library('pagination');
$data['all_vacancies'] = $this->vacancies_model->getFilteredVacancies($filterdata);
$pagconfig['base_url'] = base_url().VACANCY_OVERVIEW;
$pagconfig['total_rows'] = count($data['all_vacancies']);
$pagconfig['per_page'] = 1;
$pagconfig['uri_segment'] = 2;
$pagconfig['use_page_numbers'] = TRUE;
$this->pagination->initialize($pagconfig);
$data['links'] = $this->pagination->create_links();
$start = max(0, ( $this->uri->segment(2) -1 ) * $pagconfig['per_page']);
//This variable contains all the data necessary for a vacancy to be displayed on the vacancy overview page
$data['vacancies'] = $this->vacancies_model->getFilteredVacancies($filterdata, false, null, false, null, false, false, $pagconfig['per_page'], $start);
// Template declaration
$partials = array('head' => '_master/header/head', 'navigation' => '_master/header/navigation_dashboard', 'content' => 'dashboard/vacancy/overview', 'footer' => '_master/footer/footer');
$data['vacancygrid'] = $this->load->view('dashboard/vacancy/vacancygrid', $data, TRUE);
$this->template->load('_master/master', $partials, $data);
}
As you can see in the code i keep a variable called $filterdata, this contains all data which is used in our filters, since we don't use AJAX in this version, we need to pass it to the view every time to fill it up again and present it to the visitor.
However, using pagination this breaks because it just reloads my controller method and thus the values in $filterdata are lost.
How do I go about this?
Note: it does not have to be a clean solution, it just needs to work since this page is going offline in a couple of weeks anyway.
Thanks a lot in advance!
In my database I have many products that have a datecreated attribute.
I want to delete any product after an amount of time, like 10 or 20 days, when I refresh my home page.
This is my controller:
public function indexAction()
{
$datenow = new \DateTimeImmutable();
$datenowStringType = $datenow->format('Y-m-d');
$em = $this->getDoctrine()->getManager();
$products = $em->getRepository('ProductBundle:Product')->findAll();
foreach ($products as $produit) {
$CreatedDate = $produit->getCreatedDate();
$CreatedDate_StringType = $CreatedDate->format('Y-m-d');
$duree = '+'.$produit->getDuree();
$date_fin_duree = date('Y-m-d', strtotime($CreatedDate_StringType.$duree));
if ( strtotime($datenowStringType)<strtotime($date_fin_duree) ) {
$em->remove($produit);
}
}
array_values($products);
return $this->render('product/index.html.twig', array(
'products' => $products,
));
}
There are no errors returned, but the product isn't deleted. It could be a simple error but I searched a lot and I think it's a lack of concentration.
Please help?
$date = ''; // calculate your date here, it should be DateTime object
$qb = $em->createQueryBuilder();
$qb->delete('Product', 'p');
$qb->where('p.duree < :date');
$qb->setParameter('date', $date);
I am using PHP and SQL Server to first request an HTML template stored in my database, and then update it in a different table in the database based on form input from my website.
my update function in my model uses a get_template function to pull the text from the database, then updates the table.
public function update_domain_rules($template_content, $domain_guid) {
$sql = "UPDATE domains
SET rules = ?
WHERE domain_guid = ?";
$query = $this->db->query($sql, array($template_content, $domain_guid));
return $query->result();
}
I need to be able to replace certain words in the template I pulled with variables in my controller, specifically the start date, end date, and the name of the domain that is selected in the dropdown, and then update the database. this is the code for my controller:
function content()
{
$this->load->model('domains_model');
$this->load->model('insert_rules_model');
$domain_guid = $this->input->post('edit_domain_guid');
$start_date = $this->input->post('start_date');
$end_date = $this->input->post('end_date');
$template = $this->input->post('select_template');
if ($start_date == '') {
$start_date ==date("m/d/Y",strtotime("-1 day"));
}
if ($end_date =='') {
$end_date ==date("m/d/Y",strtotime("-1 day"));
}
$start_date_formatted = date_create($start_date);
$end_date_formatted = date_create($end_date);
$template_name = array( //create array referenced in the form_dropdown in the view
'aliens_ep1_template',
'aliens_ep2_template',
'zombies_ep1_template',
'zombies_ep2_template'
);
$template_text = $this->insert_rules_model->get_template($template);
if ($template != null) {
foreach ($template_text as $row) {
$query = $this->insert_rules_model->update_domain_rules($row->template, $domain_guid);
}
}
//redirect ("admin/insert_rules");
$data = array(
'template_name' => $template_name,
'domains' => $this->domains_model->domain_dropdown_list(),
'start_date' => $start_date,
'end_date' => $end_date,
'domain_guid' => $domain_guid
);
$this->load->view('includes/header_admin');
$this->load->view('admin/insert_rules', $data);
$this->load->view('includes/footer_admin');
}
I am very new to PHP so forgive me if my code looks ugly. I am just trying to get this thing to be functional.
I am trying to set array, but it is not getting set. Everytime the Buy function called, the array gets declared.
This is the function is controller.
public function buy() {
if($this->session->userdata('counter')){
$counter = $this->session->userdata('counter');
$this->session->set_userdata('counter', $counter + 1);
} else {
$this->session->set_userdata('counter', 1);
}
if(isset($bought)){
$name = $this->input->post('name');
$price = $this->input->post('price');
$qty = $this->input->post('qty');
$product = array('name' => $name, 'price' => $price, 'qty'=> $qty);
array_push($bought, $product);
var_dump($bought);
die();
} else {
$bought = array();
redirect("");
}
As you can see, it should remember that $bought is set, but it gets declared anew. For now I
tried to make it global, before "public function __construct()",
tried "if (!empty),
tried to put into session,
tried to find the answer across whole stackoverflow...
Please let me know if additional info needed.
Thanks a lot!
In your code when you are checking for $bought, it is not present so it is going to the else part everytime. Instead define a blank array and then set the values inside it. Try with -
if(isset($_SESSION['bought'])){
$name = $this->input->post('name');
$price = $this->input->post('price');
$qty = $this->input->post('qty');
$product = array('name' => $name, 'price' => $price, 'qty'=> $qty);
array_push($_SESSION['bought'], $product);
var_dump($_SESSION['bought']);
die();
} else {
$_SESSION['bought'] = array();
}
And start the session at top of the page.
I got it working.
I made a workaround with sgt's help, so now my code looks like this:
if($this->session->userdata('bought')){
$name = $this->input->post('name');
$price = $this->input->post('price');
$qty = $this->input->post('qty');
$product = array('name' => $name, 'price' => $price, 'qty'=> $qty);
// please see that here I just returned from old one and added new data to the old one.
// Then I just added the result to the session.
$old_session = $this->session->userdata('bought');
array_push($old_session, $product);
$this->session->set_userdata('bought', $old_session);
redirect("");
} else {
$this->session->set_userdata('bought', array());
}
I have been trying to export all of our invoices in a specific format for importing into Sage accounting. I have been unable to export via Dataflow as I need to export the customer ID (which strangely is unavailable) and also a couple of static fields to denote tax codes etc…
This has left me with the option of using the API to export the data and write it to a CSV. I have taken an example script I found (sorry can’t remember where in order to credit it...) and made some amendments and have come up with the following:
<?php
$website = 'www.example.com';
$api_login = 'user';
$api_key ='password';
function magento_soap_array($website,$api_login,$api_key,$list_type,$extra_info){
$proxy = new SoapClient('http://'.$website.'/api/soap/?wsdl');
$sessionId = $proxy->login($api_login, $api_key);
$results = $proxy->call($sessionId,$list_type,1);
if($list_type == 'order_invoice.list'){
/*** INVOICES CSV EXPORT START ***/
$filename = "invoices.csv";
$data = "Type,Account Reference,Nominal A/C Ref,Date,Invoice No,Net Amount,Tax Code,Tax Amount\n";
foreach($results as $invoice){
foreach($invoice as $entry => $value){
if ($entry == "order_id"){
$orders = $proxy->call($sessionId,'sales_order.list',$value);
}
}
$type = "SI";
$nominal = "4600";
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, $invoice['created_at']);
$invoicedOn = $date->format('d/m/Y');
$invoiceNo = $invoice['increment_id'];
$subtotal = $invoice['base_subtotal'];
$shipping = $invoice['base_shipping_amount'];
$net = $subtotal+$shipping;
$taxCode = "T1";
$taxAmount = $invoice['tax_amount'];
$orderNumber = $invoice['order_id'];
foreach($orders as $order){
if ($order['order_id'] == $orderNumber){
$accRef = $order['customer_id'];
}
}
$data .= "$type,$accRef,$nominal,$invoicedOn,$invoiceNo,$net,$taxCode,$taxAmount\n";
}
file_put_contents($_SERVER['DOCUMENT_ROOT']."/var/export/" . $filename, "$header\n$data");
/*** INVOICES CSV EXPORT END ***/
}else{
echo "nothing to see here";
}/*** GENERIC PAGES END ***/
}/*** END function magento_soap_array ***/
if($_GET['p']=="1")
{
magento_soap_array($website,$api_login,$api_key,'customer.list','Customer List');
}
else if($_GET['p']=="2")
{
magento_soap_array($website,$api_login,$api_key,'order_creditmemo.list','Credit Note List');
}
else if($_GET['p']=="3")
{
magento_soap_array($website,$api_login,$api_key,'sales_order.list','Orders List');
}
else if($_GET['p']=="4")
{
magento_soap_array($website,$api_login,$api_key,'order_invoice.list','Invoice List');
}
?>
This seems to be working fine, however it is VERY slow and I can’t help but think there must be a better, more efficient way of doing it…
Has anybody got any ideas?
Thanks
Marc
i think on put break; would be okey. because only one key with order_id, no need to looping after found order_id key.
if ($entry == "order_id"){
$orders = $proxy->call($sessionId,'sales_order.list',$value);
break;
}
and you can gather all call(s) and call it with multicall as example:
$client = new SoapClient('http://magentohost/soap/api/?wsdl');
// If somestuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'somestuff.method');
$result = $client->call($session, 'somestuff.method', 'arg1');
$result = $client->call($session, 'somestuff.method', array('arg1', 'arg2', 'arg3'));
$result = $client->multiCall($session, array(
array('somestuff.method'),
array('somestuff.method', 'arg1'),
array('somestuff.method', array('arg1', 'arg2'))
));
// If you don't need the session anymore
$client->endSession($session);
source