## Get shipment collection from order id

Normally you can get order shipment colletion like this from order:

``````\$order->getShipmentsCollection();
``````

but i’d like to retrieve the collection of shipments using order id, and i want to sort it by entity_id, so it will become like this:

``````\$shipmentCollections = \$this->shipmentModel->create()
``````

## Order of deletion with foreign key constraints,

I have a schema with three tables and foreign key ‘On Delete’ constraints as below:

``````               |      ->         FK (cascade)        ->       |
Organisation   |                                              |  Users
| - FK (cascade) Categories -> FK(restrict) -> |
``````

If I delete an organisation I want to delete the users and the categories related to it, but I can’t allow a category to be deleted if a user refers to it except in the case where the whole organisation is being deleted.

At present if I delete an organisation the category deletion fails if there’s a user referring to it. This seems to indicate that MySQl is processing the foreign key constraints on the Categories table before the Users table.

This wouldn’t be a problem if the Users in the user table were cleared before the Categories.

Is there a way to tell MySQl what order to process these FK constraints so that the tables get cleared in a specified order?

Note: I could add some code to explicitly clear the user table first, but that’s fiddly within the design of the code so I don’t want to go there yet.

Note also that the required security limits what I can do with the schema on-the-fly, so changing the FK constraints or disabling checking of them is not really an option. I can change the security to make a one-time change. I don’t want to loosen security permanently unless there’s no other way. Writing extra code as above is preferred

## Get individual products from bundled product on a order

I have a bundle product and it has been ordered, so in the admin backend, the order looks like this:

How can I get to the individual skus & qtys on this bundle products?

For example, from this order, I would like to retrieve:

``````ACULSML x 1
ACPS x 1
ACFP x 1
``````

So, I tried the following based on this answer:

``````\$order_items = \$order->getItemsCollection();
foreach (\$order_items as \$order_item) {
\$qtyOrdered = intval(\$order_item->getQtyOrdered());
\$rowTotal = floatval(\$order_item->getRowTotal());
if (\$order_item->getProductType() === 'bundle') {

\$store_id = \$order->getStoreId();
\$options = Mage::getModel('bundle/option')->getResourceCollection()
->setProductIdFilter(\$order_item->product_id)
->setPositionOrder();
\$options->joinValues(\$store_id);
\$selections = \$product->getTypeInstance(true)
->getSelectionsCollection(\$product->getTypeInstance(true)
->getOptionsIds(\$product), \$product);
foreach (\$options->getItems() as \$option) {
\$option_id = \$option->getId();
foreach (\$selections as \$selection) {
if (\$option_id === \$selection->getOptionId()) {
echo \$selection->getSku() . " x ". \$selection->getSelectionQty() ."rn";
}
}
}
}
else
{
// snipped
}
}
``````

The above code doesn’t seem to be working, because it is generating the following output:

``````ACULSML x 1.0000
ACFGSML x 1.0000
ACGLSML x 1.0000
ACLBSML x 1.0000
ACLSML x 1.0000
ACMGSML x 1.0000
ACDBSML x 1.0000
ACTGSML x 1.0000
ACCSML x 1.0000
ACDCSML x 1.0000
ACFP x 1.0000
ACPSL x 1.0000
``````

Any idea what might be wrong? How do you get to the individual item on a bundle off an order line?

## A children’s cartoon where dragons need to eat certain rocks in order to breathe fire

I remember watching a children’s animated movie several years ago, but I do not remember much. I do remember it involved a man who got trapped in a fantasy world somehow, dragons that needed to eat certain rocks in order to breathe fire, and the man defeats the villain by rapidly yelling the names of branches of science that end in “-ology.”

## A children’s cartoon where dragons need to eat certain rocks in order to breath fire

I remember watching a children’s animated movie several years ago, I do not remember much. I do remember it involved a man who got trapped in a fantasy world somehow, dragons that needed to eat certain rocks in order to breath fire, and the man defeats the villain by rapidly yelling the names of branches of science that end in -ology.

## One click order alternative – slide to pay

Mobile application is able to store (securely) credit card and users can pay small amount for some services with “one click” button (no confirmation). There is a chance users click it unintentionally (like here). Payment is available on the service page only with details like service duration and user’s location (required for price calculation).

We came with UX improvement: that button is replaced by “slider button” (full width of mobile screen in portrait mode) with text “Slide to pay 1.23\$” and user is required to slide it completely from left to right.

``````(( o )   Slide to pay 1.23\$    )
``````

The amount to be paid is small – mostly around 50c to few dollars.
The UX is consistent for iOS, Android and (mobile) web client.

## Questions

1. Is there any other alternative to avoid unwanted one click mistakes (except confirmation/popup)?
2. Is there any patent covering “slide to pay” pattern? I am aware of
slide-to-unlock only.

## Find the solution of second order differential equation with variable coefficients

$$s_1^{‘}(t) = -(mu + lambda) s_1(t) + mu s_1^{2}(t) + lambda s_{0}(t)$$

with initial conditions $$s_1(0) = 1$$. $$lambda$$ and $$mu$$ are constant, and $$s_{0}(t) = frac{mu + lambda}{mu + lambda e^{(mu+lambda)t}}$$

The differential equation is second order with variable coefficients.

Anyone can help me? I am stuch in the finding the solution of this differential equation.

## Magento 2 Add extra data to an order

I’m brand new to Magento 2 programming, although I have a number of years of PHP behind me.

I need to store an id from an external system alongside an order that that system creates.

I’ve got the code that creates the quote and turns it into an order working, alongside my custom payment method, but I can’t get it to save my extra ID.

I’ve used and altered code found elsewhere on this site to create the order:

``````public function doCreate(\$dataArray, \$order=null) {
foreach(\$dataArray->Orders as \$orderData) {
\$orderData=\$orderData->Order;
}
\$store=\$this->storeManager->getStore();
\$websiteId = \$this->storeManager->getStore()->getWebsiteId();
\$customer=\$this->customerFactory->create();
\$customer->setWebsiteId(\$websiteId);
\$customerName=explode(' ',(string)\$orderData->ShippingInfo->RecipientName);
\$firstName=\$customerName[0];
\$lastName=\$customerName[count(\$customerName)-1];
echo "First \$firstName  Last \$lastName n";
if(!\$customer->getEntityId()){
//If not avilable then create this customer
\$customer->setWebsiteId(\$websiteId)
->setStore(\$store)
->setFirstname(\$firstName)
->setLastname(\$lastName)
->setEmail((string)\$orderData->ShippingInfo->Email)
\$customer->save();
}
\$quote=\$this->quote->create(); //Create object of quote
\$quote->setStore(\$store); //set store for which you create quote
\$customer= \$this->customerRepository->getById(\$customer->getEntityId());
\$quote->setCurrency();
\$quote->assignCustomer(\$customer); //Assign quote to customer

foreach(\$orderData->OrderItems as \$item){
\$item=\$item->Item;
\$product->setPrice(\$item->Price);
\$product,
intval(\$item->Quantity)
);
}

\$shippingInfo=\$orderData->ShippingInfo;

'firstname'     => (string)\$firstName,
'lastname'      => (string)\$lastName,
'city'          => (string)\$shippingInfo->City,
'country_id'    => (string)\$shippingInfo->Country,
'region'        => (string)\$shippingInfo->State,
'postcode'      => (string)\$shippingInfo->PostalCode,
'telephone'     => (string)\$shippingInfo->PhoneNumber,
);

// Collect Rates and Set Shipping & Payment Method

->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('freeshipping_freeshipping'); //shipping method  \$shippingInfo->Service
\$quote->setPaymentMethod('cpayment'); //payment method
\$quote->setInventoryProcessed(false); //not effetc inventory

// Set Sales Order Payment
\$quote->getPayment()->importData(['method' => 'cpayment']);

// Collect Totals & Save Quote
\$quote->collectTotals()->save();

// Create Order From Quote
\$order = \$this->quoteManagement->submit(\$quote);
\$order->setEmailSent(0);
\$increment_id = \$order->getRealOrderId();
if(\$order->getEntityId()){
\$result['order_id']= \$order->getRealOrderId();
\$order->addData('external_id',\$dataArray->ExtId);//THIS IS THE ID I NEED TO SAVE
\$order->save();
}else{
}
echo "Complete: Final result isn";
print_r(\$result);
return \$result;
}
``````

If I add debugging near the end, eg `echo \$order->getData('external_id')` then it shows up, but it’s not saved in the database.

I guess I must be missing some XML somewhere, but as I said I’m brand new to Magento and finding the lack of documentation frustrating (mostly seems to be ‘copy and paste this and it will work’!)

## Help needed for Hardware Upgrade in order to bring the batch time down by 50%

I have SQL Server Express on my Laptop with following configuration

Model: HP 240 (F6Q29PA)
Processor:Intel Core I3-3110M CPU@2.4 Ghz
RAM : 2GB
HDD : 500 GB
Windows 7 Enterprise 64 bit OS

I run my batch every weekend and it takes about 15 hours to finish. Obviously this is too much for my poor home laptops and they keep burning up. So I am looking to have a more professional machine for it. The aims are

1) The machine shouldn’t overheat and burn up every two years.

2) The batch time should come down to 7-8 hours (10 hours is passable too). That way I can run my batch daily instead of just weekends.

I don’t intend to do anything else on this machine other than probably some Excel, so I don’t have any Graphics Requirement at all. Kindly help me with your suggestions. I will be happy to provide more info if required.