I am trying to understand the use of different columns present in magento sales_flat_order table..
this is what i have got so far...
protect_code
used to ensure the order being loaded is the correct one for the guest's cookie value, but not sure why magento sets this field for even logged in users..
magento table "sales_flat_order" field "protect_code" explanation
Cancelled, Invoice, Refunded ...
discount_canceled, discount_invoiced, discount_refunded
shipping_amount, shipping_canceled, shipping_invoiced, shipping_refunded
shipping_tax_amount, shipping_tax_refunded
subtotal_canceled.....
tax_amount.....
total_canceled....
then again repeated for base_discount_canceled...
I already know everything with base has to do with base currency and the other is to with store currency..
Not able to understand need of so many columns discount_canceled, discount_invoiced, discount_refunded
Magento can issue partial refunds, so can understand for refunded..
but for invoice, canceled it can rather have only one field
eg. invoice = true and use grandtotal, basegrandtotal fields ..
if this was a design issue than why this is present even in magento 2?
If i am missing some feature of magento which requires this, then i am more than interested to know about it ..
edit_increment
edit_increment
relation_child_id, relation_child_real_id, relation_parent_id, relation_parent_real_id
I found this in app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
public function createOrder()
..
..
$oldOrder = $this->getSession()->getOrder();
$originalId = $oldOrder->getOriginalIncrementId();
if (!$originalId) {
$originalId = $oldOrder->getIncrementId();
}
$orderData = array(
'original_increment_id' => $originalId,
'relation_parent_id' => $oldOrder->getId(),
'relation_parent_real_id' => $oldOrder->getIncrementId(),
'edit_increment' => $oldOrder->getEditIncrement()+1,
'increment_id' => $originalId.'-'.($oldOrder->getEditIncrement()+1)
);
..
..
$this->getSession()->getOrder()->setRelationChildId($order->getId());
$this->getSession()->getOrder()->setRelationChildRealId($order->getIncrementId());
But i am not sure , for what condition this code is executed
Some old orders in the database are having edit_increment as 1....
Few other fields..
adjustment_negative , adjustment_positive , ext_customer_id , ext_order_id
P.S- Using magento enterprise..
Related
I want to simply change the shipping method of an order on Woocommerce.
I have seen a few posts on editing shipping methods on orders but I'm not 100% clear on the exact protocol of how it works, I have a rough idea but no success yet! If you can help me to get the order to update its shipping method that would be awesome! (this is the middle of a large project so I can't share the whole plugin, let me know if you need anymore details happy to provide anything that's necessary!)
I have this small bit of code that returns me a list of orders that need shipping method updated and the new shipping method rateID that it has to be changed to, that all works fine but i have included it so you can see where it comes from.
Once the array of orders to be updated has been constructed, it then needs to be processed using the set_shipping() method. One at a time working through the array items and updating the shipping method of each, from the original to the new one provided in the toUpdate array
UPDATED: i have tried using the WC_API_Orders() class as set_shipping is a method of that. still coming up with the unrecognised error.
'Class 'Inc\Api\Callbacks\WC_API_Orders' not found'
private function updateRound()
{
if (! empty($_POST['update'])) {
$updateorderID= $_POST['orderID']; //get list of orderID to change
$updateRound= $_POST['newRound']; //list of rounds new orders want swapped to
$updateList= $_POST['update']; //uses a check box to confirm user wants to update row (stops accidentally updating the whole list)
// print_r($_POST['update']); //shows an output to check results.
$toUpdate = []; //this is the array for all the shippingmmethods to update on set order etc.
//make list of order ID's to update and their new shipping method
foreach ($updateList as $key => $value) {
$toUpdate[] = [
'orderID' => $key,
'newRound' => $updateRound[$key]
];
}
}
$absOrder = new WC_API_Orders();
foreach ($toUpdate as $updateOrder) {
//echo "</br>OrderID: ".$updateOrder['orderID']." Round updated to ".$updateOrder['newRound'];
echo "order ".$updateOrder['orderID']."updating";
$absOrder->wc_get_order($updateOrder['orderID']);
echo " order retreived";
$absOrder->set_shipping($order, $updateOrder['newRound'], 'update' );
echo "updated </br>";
}
}
This is for a very local veg delivery scheme, people can only place an order if their postcode is in the set group, so that's not so important, this shipping method we use to change from 'wed round' to 'thurs round' etc. Simple really no concern for delivery companies etc, its all in house. Tax etc. doesn't matter, it's all done elsewhere, this is simply meant to be a way of editing orders onto delivery rounds.
I have the following issue with a Magento 1.8.1 installation. I have two store views, English, which is default, and Arabic.
In the English store view if I add a product to the shopping cart I am able to modify the quantity by inputing the new quantity in the qty box and clicking Update Shopping Cart, which changes the quantity and the totals.
However, when I switch over to the Arabic store view, I can't update the quantity of any products. I input the desired quantity and press update, but the page reloads with only 1 piece of the product, and the totals are unchanged. I've tested and I've noticed that the cart only updates only for quantities over 31.
I've tried / checked the following:
This line is present in cart.phtml - getBlockHtml('formkey'); ?>
This line is present in cart.phtml - getChildHtml('form_before') ?>
There are no Javascript errors
I am using the default cart functionality, no Ajax or anything else.
I've tried replacing the cart.phtml file with the original one in the base folder, the behavior is the same.
I've tried adding the Store ID to the URL, it didn't fix the issue.
CLeared cache manually.
There are no errors in the php logs.
I've set up Manage stocks in Catalog/Inventory and reindexed, it didn't fix the issue.
Any ideas will be greatly appreciated.
Thanks,
Alex
Try to remove this code by overriding it on "local"
if (isset($params['qty'])) {
$filter = new Zend_Filter_LocalizedToNormalized(
array('locale' => Mage::app()->getLocale()->getLocaleCode())
);
$params['qty'] = $filter->filter($params['qty']);
}
from app\code\core\Mage\Checkout\controllers\CartController.php (line 183)
Create to overrride app\code\local\Mage\Checkout\controllers\CartController.php
And remove this also by overriding it on "local"
if (isset($data['qty'])) {
$cartData[$index]['qty'] = $filter->filter(trim($data['qty']));
}
from app\code\core\Mage\Checkout\controllers\CartController.php (line 428)
Create to override app\code\local\Mage\Checkout\controllers\CartController.php
Also remove this by overriding it on "local"
if (isset($params['qty'])) {
$filter = new Zend_Filter_LocalizedToNormalized(
array('locale' => Mage::app()->getLocale()->getLocaleCode())
);
$params['qty'] = $filter->filter($params['qty']);
}
from app\code\core\Mage\Checkout\controllers\CartController.php (line 327)
Create to override app\code\local\Mage\Checkout\controllers\CartController.php
I am finding some odd behavior when I try to save a product model from a script it Magento Enterprise 1.8 that has tier pricing.
Take this code for example:
// This product has a tier price
$product = Mage::getModel('catalog/product')->load(194760);
$product->setName('Changed Product Title');
$product->save();
When saving a get an exception (detailed below). However if I change nothing in the model, I do not get the exception. I have a feeling that this is due to the fact that I did not update anything so Magento does not do as much work.
// Same product, but I changed nothing and it works
$product = Mage::getModel('catalog/product')->load(194760);
$product->save();
The odd part is that I am able to save the product successfully if I am setting or modifying tier price information (pending I do not create anything that is duplicated)
// This works pending the tier price does not already exist
$mud_array = array();
$mud_array[] = array(
'website_id' => 0,
'cust_group' => 32000,
'price_qty' => 5,
'price' => 6
);
$product = Mage::getModel('catalog/product')->load(194760);
$product->setTierPrice($mud_array);
$product->save();
The exception that I am seeing is as follows:
Fatal error: Uncaught exception 'Mage_Eav_Model_Entity_Attribute_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '194760-1-0-5.0000-0' for key 'UNQ_CATALOG_PRODUCT_TIER_PRICE'' in /path/to/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php:61
So it appears that when a tier price exists in a product, and you try to change anything inside the model, it will attempt to reinsert all the tier price information.
Has anyone seen this before? Is there a way to work around this? Thanks for any help you can provide.
I had the same problem with EE 1.12, but with the "group_price" attribute. Just managed to fix the error by adding at the begging of my script
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Ok so I created a fix for this that seems to work.
In /app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php there is a function called savePriceData. From what I can gather this function is responsible for determining if we need to update or insert a tier price.
There is an if block that makes this decision to update or insert based on the information coming from the $priceObject that is passed to the function.
If you are updating a tier price from the admin panel, priceObject has two values value_id and value. These fields both point to columns in the catalog_product_entity_tier_price table. This is what happens in the first part of the if block
If you are creating a new tier price from the admin panel, priceObject has all the columns from the catalog_product_entity_tier_price table (entity_id, all_groups, customer_group_id, qty, value, and website_id). Magento then takes this information and inserts it into the catalog_product_entity_tier_price table.
The actual problem was that when you save a product from a script (aka outside the admin panel) you ALWAYS get a priceObject that contains all the information for an insert. So it will always try to do the insert into the table which if it already exists causes an integrity constraint violation.
So the fix I put together for this was really quite simple. In the second part of the if block, I am doing a check to see if the tier price already is in the table and if it is, I simply do not do the insert. Here is the code:
... first part of if statement
// somehow we need to have this not happen if it already exists
$reader = $this->_getReadAdapter();
$sql = "SELECT * FROM catalog_product_entity_tier_price WHERE ";
foreach($data as $index => $value) {
$sql .= $index . ' = ' . $value . ' AND ';
}
$sql = substr($sql, 0, -4);
$search = $reader->fetchAll($sql);
if(count($search) > 0) {
// It already exists, don't do anything
} else {
$adapter->insert($this->getMainTable(), $data);
}
Obviously, you really should make sure that you copy this file to local before you make this change (or probably better yet, rewrite it in a module). This probably is not the most 100% correct "Magento way" to do this, but I really needed to get a solution for this ASAP.
I am open to better solutions than this, but I wanted to share what I found
(Note: As I am on the Enterprise Edition of Magento, I did not want to share anymore of the source than necessary since it could be a violation of our license agreement)
I've checked the lib.php in the course folder but I don't understand what it's doing so I'm going to ask here.
I am trying to create a course with PHP and MySQL code, not with the Moodle API, by hooking up with the Moodle database.
So far, I've written a method to create a course by inserting values into the mdl_course table but nothing shows up in course homepage. It's in the database, it's enrollable and it's also visible but it doesn't show up.
I know course_sections and course_category is affected when a new course is created but how do calculate what values to put into each field?
What is modinfo in mdl_course? How do I calculate this?
How do I calculate sortorder in mdl_course? Right now I am finding the category of the where the course will be placed, then I find all the sortorders in that category, then I increment it by 1 as my new sortorder value. I'm not sure if that is correct.
Right now this is my method to create a course, obviously it is no where near complete:
public function createCourse()
{
//find category
//calculate sortorder i.e. search in mdl course for all course with category. select sortorder MAX then ++
require "/mysqli_connect.php";
$t = time();
$insert_q = "INSERT INTO mdl_course
(category, fullname, shortname, summary, startdate, maxbytes,
timecreated, newsitems, numsections, expirythreshold)
VALUES (30, 'Fullname', 'shortname', 'This is the summary', '$t', 268435456, '$t', 5, 10, 864000)";
$insert_r = mysqli_query($mysqli, $insert_q);
$insert_n = mysqli_affected_rows($mysqli);
//var_dump($insert_n);
if($insert_n == 1)
{
return true; //insert successful
}
else
{
return false;
}
}
In my experience, Moodle is not the simplest or the most transparent system to graft your own code onto. An individual entity has many different table entries. For example, a lesson will appear in mdl_lessons, mdl_course_modules, mdl_grade items, and others. I would suggest using Moodle's own API for as much as possible. If you can't do that, you could try reverse-engineering it by adding a course through the standard interface, then checking your SQL log to see what table entries it made.
Regarding the bewildering mess that is modinfo, this post on the moodle forums says that it's automatically generated. This post explains that once a course's lessons and activities are all in place, you can call rebuild_course_cache($courseid) to repopulate modinfo.
I'm trying to create configurable products programmatically in Magento 1.5.1.
I understand I need first to create simple related products, what I did. Now I manage to associate these simple products to make a configurable one.
Here is the critical part...
I keep the ids and some of the attributes values in an array, so I can later make my configurable product, but some of them are missing, I don't know which method to call.
I found this entry in Magento Wiki, that helped me and seems to fit my needs.
However, at the end the author is setting two things :
$product->setConfigurableProductsData($data);
$product->setConfigurableAttributesData($data);
and the values in the arrays have been taken in the admin page source using Firebug....and then translated into PHP arrays (array example for the first call) :
"I’ve harcoded the values for my associated products and attribute
data. You can get attribute data by viewing the source through the
admin interface and using Firebug for Firefox."
$data = array('5791'=>array('0'=>array('attribute_id'=>'491', // I already got this
'label'=>'vhs', // this too
'value_index'=>'5', // but what is value_index ?
'is_percent'=>0,
'pricing_value'=>'')),
'5792'=>array('0'=>array('attribute_id'=>'491',
'label'=>'dvd',
'value_index'=>'6',
'is_percent'=>0,
'pricing_value'=>'')));
My question is : is there a way to retrieve these values without using Firebug (which in my script won't help me a lot !), but programmatically. I already found a way to retrieve attribute values, labels, etc... using its code, but one field I don't know is value_index.
I guess this may be the option position in an option list, but not sure.
Also if someone knows a good/better way to create a configurable product in Magento, please tell me.
Any help is welcome thank you.
It seems you're asking where to retrieve the value_index value where you already have the label. Here's what I had: I didn't test this on 1.5x.
function get_attribute_id($option, $type) {
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $type);
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute->getSource()->getAllOptions();
foreach ($attributeOptions as $opts_arr) {
if (strtoupper($opts_arr['label']) == strtoupper($option)) {
return $opts_arr['value'];
}
}
return FALSE;
}
$value_index = get_attribute_id('vhs', 'media_format');
No one else seemed to mention the easiest way to figure out what the value_index of vhs is: In the backend, under
Catalog > Manage > media_format > Manage Label/Options
Inspect the source of the individual form inputs. Where you have 'vhs' you should have an input named option[value][6]
As far as I understand your question, there are two options: a) create simple products by script, put the generated id's in an array and create the configurables using the ids or b) read the id's from the admin and put them in your script. Since programming is about automation I'd definately go for option a.