Ejemplo n.º 1
0
 public function testCheckout()
 {
     /**
      * @var EventgalleryLibraryManagerCart $cartMgr
      */
     $cartMgr = EventgalleryLibraryManagerCart::getInstance();
     // CREATE
     $cart = $cartMgr->getCart();
     $this->assertEmpty($cart->getLineItems());
     $cart->addItem("test", "A_001_2013-03-17_IMG_1294.jpg", "1");
     $this->assertNotEmpty($cart->getLineItems());
     /**
      * @var EventgalleryLibraryImagelineitem $lineitem
      */
     // add line item
     $lineitems = array_values($cart->getLineItems());
     $lineitem = $lineitems[0];
     $oldPrice = $lineitem->getPrice()->getAmount();
     $lineitem->setQuantity(10);
     $cartMgr->calculateCart();
     $newPrice = $oldPrice * 10;
     $this->assertEquals($newPrice, $cart->getSubTotal()->getAmount());
     // clone line item
     $newLineitem = $cart->cloneLineItem($lineitem->getId());
     $this->assertEquals(2, $cart->getLineItemsCount());
     $this->assertEquals(11, $cart->getLineItemsTotalCount());
     // delete item
     $cart->deleteLineItem($newLineitem->getId());
     $this->assertEquals(1, $cart->getLineItemsCount());
     $this->assertEquals(10, $cart->getLineItemsTotalCount());
     /**
      * @var EventgalleryLibraryManagerShipping $shippingMgr
      */
     $shippingMgr = EventgalleryLibraryManagerShipping::getInstance();
     /** @noinspection PhpParamsInspection */
     $cart->setShippingMethod($shippingMgr->getDefaultMethod());
     $this->assertNotEmpty($cart->getShippingMethod());
     /**
      * @var EventgalleryLibraryManagerPayment $paymentMgr
      */
     $paymentMgr = EventgalleryLibraryManagerPayment::getInstance();
     /** @noinspection PhpParamsInspection */
     $cart->setPaymentMethod($paymentMgr->getDefaultMethod());
     $this->assertNotEmpty($cart->getPaymentMethod());
     /**
      * @var EventgalleryLibraryFactoryAddress $addressFactory
      */
     $addressFactory = EventgalleryLibraryFactoryAddress::getInstance();
     $data = array("firstname" => "Peter", "lastname" => "Mustermann", "address1" => "Foostreet", "address2" => "Barstreet", "address3" => "12345678", "zip" => "12345", "city" => "Footown", "state" => "Thüringen", "country" => "Barland");
     $address = $addressFactory->createStaticAddress($data, '');
     $cart->setBillingAddress($address);
     $cart->setShippingAddress($address);
     $message = "foo bar my message ist this. Can you send this?";
     $cart->setMessage($message);
     $email = "*****@*****.**";
     $cart->setEMail($email);
     $phone = "0049 12345 4567";
     $cart->setPhone($phone);
     $cartMgr->calculateCart();
     /**
      * @var EventgalleryLibraryManagerOrder $orderMgr
      */
     $orderMgr = EventgalleryLibraryManagerOrder::getInstance();
     $order = $orderMgr->createOrder($cart);
     $this->assertEquals(1, $order->getLineItemsCount());
     $this->assertEquals(10, $order->getLineItemsTotalCount());
     $this->assertNotEmpty($order->getShippingMethod());
     $this->assertNotEmpty($order->getPaymentMethod());
     $this->assertNotEmpty($order->getShippingAddress());
     $this->assertNotEmpty($order->getBillingAddress());
     $this->assertEquals('Peter', $order->getBillingAddress()->getFirstName());
     $this->assertEquals('Mustermann', $order->getBillingAddress()->getLastName());
     $this->assertEquals('Foostreet', $order->getBillingAddress()->getAddress1());
     $this->assertEquals('Barstreet', $order->getBillingAddress()->getAddress2());
     $this->assertEquals('12345678', $order->getBillingAddress()->getAddress3());
     $this->assertEquals('12345', $order->getBillingAddress()->getZip());
     $this->assertEquals('Footown', $order->getBillingAddress()->getCity());
     $this->assertEquals('Thüringen', $order->getBillingAddress()->getState());
     $this->assertEquals('Barland', $order->getBillingAddress()->getCountry());
     $this->assertEquals($email, $order->getEMail());
     $this->assertEquals($message, $order->getMessage());
     $this->assertEquals($phone, $order->getPhone());
     $total = $cart->getTotal()->getAmount();
     $subtotal = $cart->getSubTotal()->getAmount();
     $this->assertEquals($total, $order->getTotal()->getAmount());
     $this->assertEquals($subtotal, $order->getSubTotal()->getAmount());
     $this->assertEquals($cart->getShippingMethod()->getPrice()->getAmount(), $order->getShippingMethodServiceLineItem()->getPrice()->getAmount());
     $this->assertEquals($cart->getPaymentMethod()->getPrice()->getAmount(), $order->getPaymentMethodServiceLineItem()->getPrice()->getAmount());
     if ($cart->getSurcharge()) {
         $this->assertEquals($cart->getSurcharge()->getPrice()->getAmount(), $order->getSurchargeServiceLineItem()->getPrice()->getAmount());
         $manualTotal = $order->getSubTotal()->getAmount() + $order->getShippingMethodServiceLineItem()->getPrice()->getAmount() + $order->getSurchargeServiceLineItem()->getPrice()->getAmount() + $order->getPaymentMethodServiceLineItem()->getPrice()->getAmount();
     } else {
         $manualTotal = $order->getSubTotal()->getAmount() + $order->getShippingMethodServiceLineItem()->getPrice()->getAmount() + $order->getPaymentMethodServiceLineItem()->getPrice()->getAmount();
     }
     $this->assertEquals($manualTotal, $order->getTotal()->getAmount());
     // move to history
     $cart->setStatus(1);
     $this->assertEquals(1, $cart->getStatus());
     EventgalleryLibraryManagerAddress::getInstance();
 }
Ejemplo n.º 2
0
 /**
  * Updates the addresses of the cart
  *
  * validate billing address first. If this address is okay,
  * continue with the shipping address. This works for the customer
  * since there is also client side validation available
  *
  * @param EventgalleryLibraryCart $cart
  *
  * @return array Errors
  */
 public function updateAddresses(EventgalleryLibraryCart $cart = NULL)
 {
     $errors = array();
     if ($cart == NULL) {
         $cart = $this->getCart();
     }
     $xmlPath = JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_eventgallery' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'forms' . DIRECTORY_SEPARATOR;
     /**
      * USERDATA UPDATES
      */
     $userdataform = JForm::getInstance('billing', $xmlPath . 'billingaddress.xml');
     $userdataform->bind(JRequest::get('post'));
     $userdatavalidation = $userdataform->validate(JRequest::get('post'));
     if ($userdatavalidation !== true) {
         $errors = array_merge($errors, $userdataform->getErrors());
     } else {
         $phone = JRequest::getString('phone', NULL);
         if ($phone != NULL) {
             $cart->setPhone($phone);
         }
         $email = JRequest::getString('email', NULL);
         if ($email != NULL) {
             $cart->setEMail($email);
         }
         $message = JRequest::getString('message', NULL);
         if ($message != NULL) {
             $cart->setMessage($message);
         }
     }
     /**
      * ADDRESS UPDATE
      *
      */
     $addressFactory = new EventgalleryLibraryFactoryAddress();
     /**
      * @var JForm $billingform
      */
     $billingform = JForm::getInstance('billing', $xmlPath . 'billingaddress.xml');
     $billingform->bind(JRequest::get('post'));
     $billingvalidation = $billingform->validate(JRequest::get('post'));
     if ($billingvalidation !== true) {
         $errors = array_merge($errors, $billingform->getErrors());
     } else {
         $billingdata = array();
         foreach ($billingform->getFieldset() as $field) {
             $billingdata[$field->name] = $field->value;
         }
         /**
          * @var EventgalleryLibraryAddress $billingAddress
          */
         $billingAddress = $cart->getBillingAddress();
         if ($billingAddress != NULL) {
             $billingdata['id'] = $billingAddress->getId();
         }
         $billingAddress = $addressFactory->createStaticAddress($billingdata, 'billing_');
         $cart->setBillingAddress($billingAddress);
         $shiptodifferentaddress = JRequest::getString('shiptodifferentaddress', NULL);
         if ($shiptodifferentaddress == 'true') {
             /**
              * @var JForm $shippingform
              */
             $shippingform = JForm::getInstance('shipping', $xmlPath . 'shippingaddress.xml');
             $shippingform->bind(JRequest::get('post'));
             $shippingvalidation = $shippingform->validate(JRequest::get('post'));
             if ($shippingvalidation !== true) {
                 $errors = array_merge($errors, $shippingform->getErrors());
             } else {
                 $shippingdata = array();
                 foreach ($shippingform->getFieldset() as $field) {
                     $shippingdata[$field->name] = $field->value;
                 }
                 $shippingAddress = $cart->getShippingAddress();
                 if ($shippingAddress != NULL && $shippingAddress->getId() != $billingAddress->getId()) {
                     $shippingdata['id'] = $shippingAddress->getId();
                 }
                 /**
                  * @var EventgalleryLibraryAddress $shippingAddress
                  */
                 $shippingAddress = $addressFactory->createStaticAddress($shippingdata, 'shipping_');
                 $cart->setShippingAddress($shippingAddress);
             }
         } elseif ($shiptodifferentaddress == 'false') {
             $cart->setShippingAddress($billingAddress);
         }
     }
     return $errors;
 }