Shopware - Getting documentCollection in orderRepository - php

I am currently facing a strange behaviour on shopware 6.
What I need is to get order's documents informations when the order is refunded (invoice number & creditNote number).
Here is how I am getting the documentEntity in the orderRepository:
$criteria = new Criteria([$orderId]);
$criteria->addAssociation('lineItems');
$criteria->addAssociation('documents');
$orderObject = $this->orderRepository->search($criteria, $context);
$documents = $orderObject->first()->getDocuments();
Normal behaviour
When the order state is set to "refunded_partially", $documents perfectly contains what it should.
The problem
When the order state is set to "refunded", $documents is empty and I have no errors in logs.
Maybe I overlooked but I saw no differences between the dump I made on $orderObject when it's "refunded" and when it's "refunded_partially".
Does someone have a clue on how to manage this correctly?

AS this one is pretty tricky to do, I recommand you to use a specific event to work with documents. The event is triggered when a document is created for an order (invoice, credit note, etc.)
Example here

Related

SilverStripe Display Logic for ListboxField not working

SilverStripe: v4
Module used: https://github.com/unclecheese/silverstripe-display-logic
Hello and good day!
I'm in the Security page (Lists of Members) and was trying to display a ListboxField upon a certain string or value is found on another ListboxField.
.
With The image above, I wanted to select or input in the Groups field the Sales Representative role, and once the Sales Representative is present in the Groups, that's the moment I shall display another field
Here's my code snippet
$codesList = Member::get()->column('Code');
$codes = ListboxField::create(
'AccountPurchases',
'Account Purchases',
$codesList);
$fields->insertAfter('DirectGroups', $codes);
$codes->displayIf("DirectGroups")->contains("Sales Representative");
But the problem is, no matter what I did (1: dev/build?flush=1, 2: refresh the page, 3: restart the app) the desired field named $codes still won't appear.
But if I'm applying it to a normal field like the FirstName (which is a simple TextField), it's working perfectly fine...
$codesList = Member::get()->column('Code');
$codes = ListboxField::create(
'AccountPurchases',
'Account Purchases',
$codesList);
$fields->insertAfter('DirectGroups', $codes);
$codes->displayIf("FirstName")->contains("Sales Representative");
Any ideas how to perform my desired output?
For non-standard form fields, you'll need to use the display-logic wrapper. https://github.com/unclecheese/silverstripe-display-logic#dealing-with-non-standard-form-fields
The definition of "non-standard" is a bit hard to find, but in my experience it's anything non-plain-html-input. Listbox is a fancy front-end thing, so it qualifies. The examples in the docs can be confusing, but if you are using SS4 and the latest display-logic, then use Wrapper::create instead of DisplayLogicWrapper::create. If you wrap it, it should work.
$codesList = Member::get()->column('Code');
$codes = Wrapper::create(
ListboxField::create('AccountPurchases','Account Purchases',$codesList);
)->displayIf("DirectGroups")->contains("Sales Representative")->end();
$fields->insertAfter('DirectGroups', $codes);

Switching to GetSingleItem instead of findItemsAdvanced with the ebay-api

I am using the ebay-api's to pull out listing information using the itemId the user enters to import the current live auction on ebay into my site. I have been using the FindItemsAdvanced which is pretty straight forward grabbing the information using the SingleXMLElement
$itemid = (string) $xml->searchResult->item->itemId;
$shipcost = (string) $xml->searchResult->item->shippingInfo->shippingServiceCost;
I dont really need to use the FindItemsAdvanced because some information is missing, ie: quantity of a item listed.
I have looked at the documentation for GetSingleItem and it doesnt have a searchResult member, my question is, how is the above done with GetSingleItem to get the details.
This is the process i used but cant grab any details
url2 is - http://open.api.ebay.com/shopping?callname=GetSingleItem&responseencoding=XML&appid=myIdApp&siteid=0&version=967&ItemID=192401461174&IncludeSelector=Details
then the contents
$resp2 = file_get_contents($url2);
then the xml object
$xml2 = new SimpleXMLElement($resp2);
At this stage i have my object but i cant extract any details like a can with FindItemsAdvanced
Thanks to the comments i'm adding more information, the file_get_contents only gives me this
2017-12-24T12:33:55.736Z Success E1033_CORE_APILW_18542200_R1 1033 false 192401461174 2018-01-17T10:29:17.000Z 2017-12-18T10:29:17.000Z http://www.ebay.com/itm/Aspire-CF-SUB-OHM-Mod-Battery-Ecig-Vape-Kit-Carbon-Fibre-Aspire-k3-Samsung-25r-/192401461174 FixedPriceItem wigan, Lancashire PayPal http://thumbs3.ebaystatic.com/pict/1924014611748080_1.jpg https://i.ebayimg.com/00/s/NTQ1WDczMQ==/z/6PkAAOSwttFaD~0~/$_1.PNG?set_id=8800005007 https://i.ebayimg.com/00/s/NzIwWDI5MA==/z/kccAAOSwtGlZCa0C/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/OTAyWDYwMA==/z/Gk8AAOSw42JZCa0D/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/Nzg3WDExODE=/z/eNkAAOSwQcJaBAo8/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/OTAwWDkwMA==/z/zQgAAOSwyP5aD~1K/$_1.JPG?set_id=8800005007 https://i.ebayimg.com/00/s/NTAwWDUwMA==/z/6RIAAOSwttFaD~1L/$_1.PNG?set_id=8800005007 wn69jt 183498 Health & Beauty:E Cigarettes, Vapes & Accs:E Cigarettes, Vapes & Mods 5 improveyourlife Purple 525 100.0 0 31.94 23.9 Active 0 Worldwide UK P23DT21H55M22S 184 26395:183497:183498 GB 14 days Returns Accepted Only if broken Buyer false false 0 1000 New false 0 false true true
I understand i need to get the xml into a string to use namespaces but i'm not sure how to do that. The crazy thing is, the only thing i need out of GetSingleItem is the quantity because FindItemsAdvanced does not have it.
Try using $xml2 = simplexml_load_string($resp2); and then you should be able to get the information needed normally, with $quantity = $xml2->Item->Quantity;.
As a tip, I highly recommend you give a try to this SDK. I am using it for a long time, to manage multiple shops and it's extremely helpful. Saved me a huge amount of time. The guy who created it also made a ton of examples. You could have a look at those before using the SDK, and you'll see how much simpler everything is.

Facebook Ads - update url_tags

I am using Facebook Ads SDK v2.6.0 and I would like to update the url_tags of an Ad.
$ad->creative['id'] contains the AdCreative's ID and is OK since read() returns actual data.
$creative = new AdCreative($ad->creative['id']);
$creativeData = $creative->read([
'link_url',
'name',
'object_story_spec',
'object_story_id',
'url_tags'
]); // $creativeData->url_tags is OK and contains tags we have now
$creative->setData(['url_tags' => "a=b&c=d"]);
$creative->update();
Then everything seems to work fine, the response is received and the result is {"success": true}.
No exceptions are thrown and everything goes smooth, but the url_params is updated neither in Facebook Ads Manager nor the field $creativeData->url_tags when I run the script again.
P.S. I was able to update the object_story_spec of AdCreative, but I would precisely since it wouldn't cause the ad to be re-approved.
Best regards, Alexander
It looks like url_tags are not one of the mutable fields of an AdCreative object, so you will have to re-create the creative with the new url_tags in order to achieve this.
The following section of the docs outlines which fields are mutable:
https://developers.facebook.com/docs/marketing-api/reference/ad-creative#Updating

Creating configurable product programmatically

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.

Magento - Programmatically reorder

I am currently making a module that requires me to take an order object and make it reorder itself.. thus, creating a new order in the backend with the exact same items and credentials.
This is the code that i have thus far… it doesn’t seem to reorder the item or create and add another backend order.
$personsOrder = Mage::getModel(’sales/order’);
$personsOrder->loadByIncrementId($order[’model_order_id’]);
$order_model = Mage::getSingleton(’adminhtml/sales_order_create’);
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
/*
$order_model->save();
$order_model->place();
$order_model->sendNewOrderEmail();
*/
Any help is greatly appreciated!!
$orderId= $YOUR_ORDER_NUMBER;
$personsOrder = Mage::getModel('sales/order')->load($orderId);
$order_model = Mage::getSingleton('adminhtml/sales_order_create');
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
$order_model->createOrder();
My first thought is that you should be using $order->getIncrementId() on line 2 rather than $order['model_order_id'], but I'm not sure where you're getting $order from in the first place. Have you checked that $order['model_order_id'] is actually returning a valid increment ID? I don't see model_order_id as a field in the database anywhere...
I'd be suggesting that you getting your IDE and XDebug working so that you can inspect the objects as you work with them and understand what's going on.
Cheers,
JD
If the order that you have placed the first time around is also created through coding and not from store front then you need to make sure that you have added an entry in the sales_flat_quote_item table. Otherwise that order cannot be reordered. So make sure it's not the case with your order creation.

Categories