/** * @param OrderEvent $event * @throws \Exception */ public function update_address(OrderEvent $event) { if ($event->getOrder()->getDeliveryModuleId() === LocalPickup::getModCode()) { $address_id = $event->getOrder()->getDeliveryOrderAddressId(); $address = OrderAddressQuery::create()->findPk($address_id); if ($address !== null) { $config = new ConfigQuery(); $address1 = $config->read("store_address1"); $address2 = $config->read("store_address2"); $address3 = $config->read("store_address3"); $zipcode = $config->read("store_zipcode"); $city = $config->read("store_city"); $country = $config->read("store_country"); $name = $config->read("store_name"); if ($address1 !== null && $zipcode !== null && $city !== null && $country !== null) { $address_event = new OrderAddressEvent($address->getCustomerTitleId(), $address->getFirstname(), $address->getLastname(), $address1, $address2, $address3, $zipcode, $city, $country, $address->getPhone(), $name); $address_event->setOrderAddress($address); $event->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_ADDRESS, $address_event); } } else { throw new \Exception("Error: order deliery address doesn't exists"); } } }
/** * @depends testCreate * * @param OrderModel $order */ public function testUpdateAddress(OrderModel $order) { $deliveryRef = uniqid('DELREF'); $orderAddress = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId()); $title = $orderAddress->getCustomerTitleId() == 3 ? 1 : 3; $country = $orderAddress->getCountryId() == 64 ? 1 : 64; $orderAddressEvent = new OrderAddressEvent($title, 'B', 'C', 'D', 'E', 'F', 'G', 'H', $country, 'J', 'K'); $orderAddressEvent->setOrderAddress($orderAddress); $orderAddressEvent->setOrder($order); $this->orderAction->updateAddress($orderAddressEvent); $newOrderAddress = OrderAddressQuery::create()->findPk($orderAddress->getId()); $this->assertEquals($title, $orderAddressEvent->getOrderAddress()->getCustomerTitleId()); $this->assertEquals('B', $orderAddressEvent->getOrderAddress()->getFirstname()); $this->assertEquals('C', $orderAddressEvent->getOrderAddress()->getLastname()); $this->assertEquals('D', $orderAddressEvent->getOrderAddress()->getAddress1()); $this->assertEquals('E', $orderAddressEvent->getOrderAddress()->getAddress2()); $this->assertEquals('F', $orderAddressEvent->getOrderAddress()->getAddress3()); $this->assertEquals('G', $orderAddressEvent->getOrderAddress()->getZipcode()); $this->assertEquals('H', $orderAddressEvent->getOrderAddress()->getCity()); $this->assertEquals($country, $orderAddressEvent->getOrderAddress()->getCountryId()); $this->assertEquals('J', $orderAddressEvent->getOrderAddress()->getPhone()); $this->assertEquals('K', $orderAddressEvent->getOrderAddress()->getCompany()); $this->assertEquals($title, $newOrderAddress->getCustomerTitleId()); $this->assertEquals('B', $newOrderAddress->getFirstname()); $this->assertEquals('C', $newOrderAddress->getLastname()); $this->assertEquals('D', $newOrderAddress->getAddress1()); $this->assertEquals('E', $newOrderAddress->getAddress2()); $this->assertEquals('F', $newOrderAddress->getAddress3()); $this->assertEquals('G', $newOrderAddress->getZipcode()); $this->assertEquals('H', $newOrderAddress->getCity()); $this->assertEquals($country, $newOrderAddress->getCountryId()); $this->assertEquals('J', $newOrderAddress->getPhone()); $this->assertEquals('K', $newOrderAddress->getCompany()); }
public function updateAddress($order_id) { if (null !== ($response = $this->checkAuth(AdminResources::ORDER, array(), AccessManager::UPDATE))) { return $response; } $message = null; $orderUpdateAddress = new OrderUpdateAddress($this->getRequest()); try { $order = OrderQuery::create()->findPk($order_id); if (null === $order) { throw new \InvalidArgumentException("The order you want to update does not exist"); } $form = $this->validateForm($orderUpdateAddress, "post"); $orderAddress = OrderAddressQuery::create()->findPk($form->get("id")->getData()); if ($orderAddress->getId() !== $order->getInvoiceOrderAddressId() && $orderAddress->getId() !== $order->getDeliveryOrderAddressId()) { throw new \InvalidArgumentException("The order address you want to update does not belong to the current order not exist"); } $event = new OrderAddressEvent($form->get("title")->getData(), $form->get("firstname")->getData(), $form->get("lastname")->getData(), $form->get("address1")->getData(), $form->get("address2")->getData(), $form->get("address3")->getData(), $form->get("zipcode")->getData(), $form->get("city")->getData(), $form->get("country")->getData(), $form->get("phone")->getData(), $form->get("company")->getData()); $event->setOrderAddress($orderAddress); $event->setOrder($order); $this->dispatch(TheliaEvents::ORDER_UPDATE_ADDRESS, $event); } catch (\Exception $e) { $message = $e->getMessage(); } $params = array(); if ($message) { $params["update_status_error_message"] = $message; } $params["tab"] = $this->getRequest()->get("tab", 'bill'); return $this->generateRedirectFromRoute("admin.order.update.view", $params, ['order_id' => $order_id]); }
/** * @param OrderAddressEvent $event */ public function updateAddress(OrderAddressEvent $event) { $orderAddress = $event->getOrderAddress(); $orderAddress->setCustomerTitleId($event->getTitle())->setCompany($event->getCompany())->setFirstname($event->getFirstname())->setLastname($event->getLastname())->setAddress1($event->getAddress1())->setAddress2($event->getAddress2())->setAddress3($event->getAddress3())->setZipcode($event->getZipcode())->setCity($event->getCity())->setCountryId($event->getCountry())->setPhone($event->getPhone()); $orderAddress->save(); $event->setOrderAddress($orderAddress); }