Exemple #1
0
 /**
  * Start mocking around.
  *
  * @param ShoppingCart shoppingCart The current shopping cart.
  * @param ZenMagick\StoreBundle\Entity\Address shippingAddress Optional shipping address; default is <code>null</code>.
  */
 public static function startMock(ShoppingCart $shoppingCart, $shippingAddress = null)
 {
     global $order, $shipping_weight, $shipping_quoted, $shipping_num_boxes, $total_count, $order_total_modules;
     global $_order, $_shipping_weight, $_shipping_quoted, $_shipping_num_boxes, $_total_count, $_order_total_modules;
     if (self::$mock++) {
         // already mocking
         return;
     }
     // save originals
     $_order = $order;
     $_shipping_weight = $shipping_weight;
     $_shipping_quoted = $shipping_quoted;
     $_shipping_num_boxes = $shipping_num_boxes;
     $_total_count = $total_count;
     $_order_total_modules = $order_total_modules;
     if (!isset($_SESSION['cart'])) {
         $_SESSION['cart'] = new \ZenMagick\ZenCartBundle\Compat\ShoppingCart();
     }
     // get total number of products, not line items...
     $total_count = 0;
     foreach ($shoppingCart->getItems() as $item) {
         $total_count += $item->getQuantity();
     }
     //$order_total_modules = new ZenCartOrderTotal();
     if (null == $order || !$order instanceof ZenCartCheckoutOrder) {
         $mockOrder = new ZenCartCheckoutOrder();
         $mockOrder->setContainer(Runtime::getContainer());
         $mockOrder->setShoppingCart($shoppingCart);
         if (null != $shippingAddress) {
             $mockOrder->setShippingAddress($shippingAddress);
         }
         $order = $mockOrder;
     }
     // START: adjust boxes, weight and tare
     $shipping_quoted = '';
     $shipping_num_boxes = 1;
     $shipping_weight = $shoppingCart->getWeight();
     $za_tare_array = preg_split("/[:,]/", SHIPPING_BOX_WEIGHT);
     $zc_tare_percent = $za_tare_array[0];
     $zc_tare_weight = $za_tare_array[1];
     $za_large_array = preg_split("/[:,]/", SHIPPING_BOX_PADDING);
     $zc_large_percent = $za_large_array[0];
     $zc_large_weight = $za_large_array[1];
     switch (true) {
         // large box add padding
         case SHIPPING_MAX_WEIGHT <= $shipping_weight:
             $shipping_weight = $shipping_weight + $shipping_weight * ($zc_large_percent / 100) + $zc_large_weight;
             break;
         default:
             // add tare weight < large
             $shipping_weight = $shipping_weight + $shipping_weight * ($zc_tare_percent / 100) + $zc_tare_weight;
             break;
     }
     if ($shipping_weight > SHIPPING_MAX_WEIGHT) {
         // Split into many boxes
         $shipping_num_boxes = ceil($shipping_weight / SHIPPING_MAX_WEIGHT);
         $shipping_weight = $shipping_weight / $shipping_num_boxes;
     }
     // END: adjust boxes, weight and tare
 }
 /**
  * Populate info.
  *
  * @param ShoppingCart shoppingCart The shopping cart.
  */
 protected function populateInfo(ShoppingCart $shoppingCart)
 {
     // general stuff
     // TODO: where from/to??
     $languageId = $this->container->get('settingsService')->get('storeDefaultLanguageId');
     // TODO: move all cart/session values into ShoppingCart
     $currencyCode = $this->container->get('session')->get('currency');
     $couponAmount = 0;
     $couponCode = null;
     if (null != ($couponCodeId = $this->container->get('session')->get('cc_id'))) {
         $coupon = $this->container->get('couponService')->getCouponForId($couponCodeId, $languageId);
         if (null != $coupon) {
             $couponCode = $coupon->getCode();
             $couponAmount = $coupon->getAmount();
         }
     }
     $shippingMethod = $shoppingCart->getSelectedShippingMethod();
     $paymentType = $shoppingCart->getSelectedPaymentType();
     $orderStatus = DEFAULT_ORDERS_STATUS_ID;
     if (null != $paymentType && null !== ($pos = $paymentType->getOrderStatus())) {
         $orderStatus = $pos;
     }
     $tax = 0;
     $taxGroups = array();
     foreach ($shoppingCart->getItems() as $item) {
         $itemTotal = $item->getItemTotal(false) + $item->getOneTimeCharge(false);
         $itemTotalPlusTax = $item->getItemTotal(true) + $item->getOneTimeCharge(true);
         $itemTax = $itemTotalPlusTax - $itemTotal;
         $productTaxRate = $item->getTaxRate();
         $description = $productTaxRate->getDescription();
         if (!array_key_exists($description, $taxGroups)) {
             $taxGroups[$description] = 0;
         }
         $taxGroups[$description] += $itemTax;
         $tax += $itemTax;
     }
     $info = array('order_status' => $orderStatus, 'currency' => $currencyCode, 'currency_value' => $this->container->get('currencyService')->getCurrencyForCode($currencyCode)->getRate(), 'payment_method' => null != $paymentType ? $paymentType->getTitle() : '', 'payment_module_code' => null != $paymentType ? $paymentType->getId() : '', 'coupon_code' => $couponCode, 'shipping_method' => null != $shippingMethod ? $shippingMethod->getName() : '', 'shipping_module_code' => null != $shippingMethod ? $shippingMethod->getShippingId() : '', 'shipping_cost' => null != $shippingMethod ? $shippingMethod->getCost() : '', 'subtotal' => $shoppingCart->getSubTotal(), 'shipping_tax' => 0, 'tax' => $tax, 'total' => $shoppingCart->getTotal() + $couponAmount, 'tax_groups' => $taxGroups, 'comments' => $shoppingCart->getComments());
     $this->info = array_merge($this->info, $info);
     if ($this->container->get('settingsService')->get('apps.store.assertZencart', false)) {
         $this->assertInfo(false);
     }
 }