Magento update customer group prices for products - api

I'm trying to update the customer group prices in Magento using Mage (as I cannot find a way to do so in the SOAP V2 API). I've found a StackOverflow example, however it doesn't work for me. The code I'm using is as follows:
<?php
include_once '../App/Mage.php';
Mage::app();
$productID = $_GET["id"];
$product = Mage::getModel('catalog/product')->load($productID);
$groupPricingData = array(array('price_id'=>1,'website_id'=>0,
'cust_group'=>3, 'price'=>666));
$product->setData('group_price',$groupPricingData);
$product->save();
echo "true";
?>
I get the following error if I use a product that has any customer prices already set. If I try a product with no existing prices, it doesnt error, but the customer group price is not created.
SCREAM: Error suppression ignored for
( ! ) Fatal error: Uncaught exception 'Mage_Eav_Model_Entity_Attribute_Exception' with
message 'SQLSTATE[23000]: Integrity constraint violation: 1062
Duplicate entry '24-0-3-0' for key 'CC12C83765B562314470A24F2BDD0F36'' in
C:\wamp\www\magento\app\code\core\Mage\Core\Model\Config.php on line 1348
( ! ) Mage_Eav_Model_Entity_Attribute_Exception: SQLSTATE[23000]:
Integrity constraint violation: 1062 Duplicate entry '24-0-3-0' for
key 'CC12C83765B562314470A24F2BDD0F36' in
C:\wamp\www\magento\app\code\core\Mage\Core\Model\Config.php on line 1348

I have been scouring the web for an answer to how to properly "update" group price on Magento Product records and have been unsuccessful. Pouring over Magento's source code hasn't gotten me anywhere either. I have however, discovered two solutions on how to clear out the existing group price, so that you do not receive this error.
1 - Direct SQL query to remove the existing group price data
$coreResource = Mage::getSingleton('core/resource');
$conn = $coreResource->getConnection('core_write');
$table_name = $coreResource->getTableName('catalog_product_entity_group_price');
$conn->delete($table_name, array('entity_id = '.$product->getId()));
2- Set the group price for the product to be empty, and save the product.
$product->setData('group_price', array())->save();
Performing either of these (no need to do both) PRIOR to setting your group price data and saving the product, will avoid the Integrity constraint violation, since they effectively remove the existing group price for the product. Approach 1 feels sketchy because we usually do not make direct sql queries and instead rely on model classes to have methods already built in place for us to encapsulate this logic, but in my test environment (Magento 1.9) it works. Approach 2 may seem safer, however it is more resource intensive since it is saving the entire product record, when all we really need to do is update/delete the existing group price. Plus it requires a redundant save since we're "saving to remove" the existing group price.
I recommend re-indexing Product Prices afterwards, as group price data is also stored in 'catalog_product_index_group_price'.

Try to use this extension for magmi group prices:
https://github.com/tim-bezhashvyly/magmi-grouped-price-plugin

Related

Adding new product with category tree - specific price problems

I installed an add-on for bulk action (called ba_importer v 1.1.24), I upload an Excel file with my data and create a group of products.
I can set the categories' tree or manually add ID of main categories and associated. I tried with no luck to use the tree features (like Home/Products/etc) and so I use all the ID of main category and all the associated. The result is a product with the correct categories set, but with no specific price from the customer group linked to a category.
I tried to edit a single product, remove all categories and set it one by one (set one, save, set one, save etc.) and then the specific price from the group linked to a category appears to the product.
Is there a better solution? I'm thinking about make a personal PHP page that reads an Excel file and sets all the information about the product, but I'm scared to face the same problem with the specific price. 
There is no such thing as "category-related specific price",
if you have specific prices tied to customer groups , these are created as a result of the add/update product action with ps_specific_price DB entries having id_group with your restricted ID.
It is likely that the bulk module acts directly with DB queries to speed up things and bypasses this operation, I've seen this behaviour with those kind of modules in the past.
Since you are talking of a paid add-on, I would definitely seek help from the developer.

Error in Updating Square Order after creating invoice

I am using Square SDK for dotnet and I am creating an order and then creating invoice and then updating the same order. I am using same api key, same customer and same location for all these operations but it is breaking at update call giving following error.
Category: "AUTHENTICATION_ERROR"
Code: "FORBIDDEN"
Detail: "LineItems cannot be modified for orders owned by another application."
Field: "order.line_items"
The error should be better, but essentially once you actually create the invoice, you can't edit the line items that would affect the amount. Per the documentation:
Updating an order. You cannot update order fields (such as line items, taxes, and discounts) that change the order amount. To update these order fields, you must cancel the invoice, which also cancels the order (sets the order status to CANCELED). You then create a new order and a new invoice. You can update order fields that do not change the order amount.

Duplicate keys when adding products in Vuetify Data Table

I am currently using a Vuetify Data Table where you can add products to. In the end I want to do a calculation based on the price of all those products. The products all have an ID, but when I add those products to the Data Table it gives me the following error:
Duplicate keys detected: '12'. This may cause an update error.
I understand this happens because I use the ID of the product. But how can I prevent that it is giving me this error? Should I pass a completely different ID instead of the one of the product itself? I might need the product ID later. I would like to know what would be the best solution. Thanks in advance.
I suggest you to add a column with an unique id. If you have an array of objects:
array.forEach((item, i) => {
item.subId = i + 1;
})
Then in your Data Table set the item-key to subId.

Bigcommerce: edit an existing order shipment address

I imported 10k legacy orders with the wrong state. How do I fix it? When I use the order shipment update endpoint PUT /orders/{order_id}/shipments/{id} I get an error that the shipping_address field is not writable. What do I do?
I'm using the API docs here: https://developer.bigcommerce.com/api-reference/orders/orders-api/order-shipments/putordersorderidshipmentsid
It isn't possible to directly write to the order shipment address state field, but for context, that mirrors the behavior you'd see when working with order shipments in the control panel. The best solution would be to delete the shipments with the incorrect state and re-create the shipments.
Edit:
There are 2 options to re-create the shipment with the correct address: The first is to update the order by adding a new shipping address containing the correct state and use that shipping address when you re-make the shipment. Although existing order shipping addresses can't be edited, the order shipping address array is additive. So you can update the order by adding a new shipping address and use that order_address_id to create the new shipment. The second option would be to delete the entire order with the incorrect shipping address and re-import it with the correct data, then re-create the shipment.
On the orders resource, we are scoping a feature request to make shipping addresses editable. (This would align with what you're able to do when editing an order through the control panel). I'll keep you posted in this thread when there's an update on that, although the best solution in the meantime would be to use one of the options outlined above.

Integrity error where try to save a supplier invoices

I build a module who increase stock on supplier invoices. Work fine on devel server but when I pun on work server I have this error. How can I corret this error?
Integrity Error
The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it - creation/update: a mandatory field is not correctly set
[object with reference: Purchase Order Line - purchase.order.line]
Integrity Error on OpenERP occur because of two possibility (mentioned on the description of error):
When you create or update a record, a mandatory field is not correctly set or is not filled. What field? One of field in your object (mentioned). In your case: purchase.order.line.
When you delete a record, the record you want to delete is used by another record and set as a mandatory field (required) from the python code.
My guess, if you get the error when you create/update a record (Purchase Order), maybe you create/update the order lines, but one of mandatory field in order lines is empty.