public function prices($internalUse = FALSE) { $this->CashAndCarry = new CashAndCarry(); if (!empty($this->request->data['zip'])) { $zipCode = $this->request->data['zip']; } else { $zipCode = null; } if (!empty($this->data['sponsor_id'])) { $presenter = $this->Presenter->findById($this->data['sponsor_id']); } if (!empty($presenter)) { $promoterId = 0; $presenterId = $presenter['Presenter']['id']; } else { $promoterId = 0; $presenterId = 0; } if (empty($this->request->data['items'])) { $items = array(); } else { $items = $this->ShoppingCartItem->pruneItems($this->request->data['items'], false, $this->request->data['productcredits']); } $this->Session->write('user_id', $this->request->data['user_id']); $userId = $this->Session->read("user_id"); if (empty($this->request->data['productcredits'])) { $productcredits = null; } else { $productcredits = Money::fromPennies((int) $this->request->data['productcredits']); //check if product credits is greater than their balance $balance = $this->ProductCredit->balance(Configure::read("market_id"), $presenterId, $userId); if ($productcredits->isGreaterThan($balance)) { $productcredits = $balance; } } //used for removing the ycash exempt value from the amount ycash can be applied $discount_exclusion = Money::fromFloat(0); foreach ($items as &$item) { //items that are y-cash excluded if (in_array($item['sku'], ProductGlobal::yCashExcluded())) { App::import("Model", "Item"); $this->Item = new Item(); $limit_item = $this->Item->detailsBySku($item['sku'], $this->Session->read('Config.language'), true); $discount_exclusion->add(Money::fromFloat($limit_item['price'] * $item['qty'])); } if (empty($item['coupons']) || empty($item['coupons'][0])) { continue; } $couponIds = $item['coupons']; unset($item['coupons']); $coupons = $this->User->CouponPresenterUser->availableCouponsById($presenterId, $userId, $couponIds); foreach ($coupons as $coupon) { $item['coupons'][$coupon['id']] = array("discount_percentage" => $coupon['discount_percentage'], "discount_flat" => $coupon['discount_flat'], "name" => $coupon['name']); } } $toUseCoupons = array(); $user_coupons = $this->User->CouponPresenterUser->availableCouponsById($presenterId, $userId, $this->ShoppingCartItem->getCoupons()); foreach ($user_coupons as $coupon) { $toUseCoupons[$coupon['id']] = $coupon; } //This is for determining if use the discounted prices for coupon $is_presenter = $this->Session->check('presenter_id'); $result = $this->Order->getOrderCosts($zipCode, $items, $productcredits, $toUseCoupons, FALSE, $is_presenter, $userId); //y-cash excluded items $product_creditable = $result['total']['market_commissionable_total']->copy()->subtract($discount_exclusion); //check if discounts are larger than the adjusted discount limit if ($result['total']['productcredits'] > $product_creditable) { //adjust product credit amount $productcredits = $result['total']['product_creditable']; //get new order totals $result = $this->Order->getOrderCosts($zipCode, $items, $productcredits, $toUseCoupons, FALSE, $is_presenter, $userId); } // Add free catalog // $items = $this->addFreeCatalog($result, $items); // if ($result['total']['freeCatalog'] == true) { // $result = $this->Order->getOrderCosts($zipCode, $items, $productcredits, $toUseCoupons, $is_presenter, $userId); // } //add product creditable node $result['total']['product_creditable'] = $product_creditable; //last_quote_date $result['total']['last_quote_date'] = date('Y-m-d'); //set order limits $market_id = $this->request->data['market_id'] ? $this->request->data['market_id'] : Configure::read("market_id"); //market touch point $nfr_order_limit = $this->TraitCountry->getTrait($market_id, 'nfr_order_limit'); if (!empty($nfr_order_limit)) { $order_limits = $this->_getOrderLimits($market_id); $result['total']['orderLimit'] = Money::fromFloat($order_limits['market_limit']); $result['total']['orderLimitUsed'] = $order_limits['used']; $result['total']['orderLimitRemaining'] = Money::fromFloat($order_limits['market_limit'])->subtract($order_limits['used']); $result['total']['orderLimitThrottleValue'] = $order_limits['period_value']; $result['total']['orderLimitThrottlePeriod'] = $order_limits['period']; $result['total']['rolling_used'] = $order_limits['rolling_used']; $result['total']['rollingRemaining'] = Money::fromFloat($order_limits['market_limit'])->subtract($order_limits['rolling_used']); } $result['total']['time'] = date("Y-m-d H:i:s"); $this->Session->write('last_quote_date', date('Y-m-d')); if (!$internalUse) { $this->sendSuccess($result); } else { return $result; } }
/** * Items with free shipping * @return array */ public static function freeShipping() { // $free = [ // 'US-70015-01', // convention guest pass // 'US-70015-02', // convention guest pass // 'US-70015-03', // convention guest pass // 'AU-80002-05', // AU NZ Presenter kit Plus You // 'CA-80002-05', // CA Presenter kit Plus You // 'CA-80202-05', // CA French Presenter Kit Plus You // 'DE-80302-05', // DE Presenter Kit Plus You // 'MX-80102-05', // MX Presenter Kit Plus You // 'UK-80002-05', // UK Presenter Kit Plus You // 'US-80002-05', // US Presenter Kit Plus You // 'US-80102-05', // US Latina Presenter Kit Plus You // ]; $itemPromotionTimes = ClassRegistry::init('ItemPromotionTimes'); $free = $itemPromotionTimes->getFreeShipping(); return array_merge($free, ProductGlobal::convention()); }
private function discounts($item, $cartItem, $commission, $presenter_market_id, $market_id) { $this->orderObject->discount = Money::fromFloat(0); if (!empty($cartItem['coupons'])) { foreach ($cartItem['coupons'] as $couponId => $coupon) { if ($couponId == 0) { continue; } if ($item['type'] == 5 && $coupon['discount_percentage'] == 50) { continue; } //supply items cannot have half off coupons if ($item['item_type_id'] == Item::TYPE_CONVENTION_TICKET) { continue; } // convention tickets cannot have coupons if (count($this->orderObject->discounts) >= $cartItem['qty']) { continue; } // $this->orderObject->commissionSubtotal = $commission->copy()->times($cartItem['qty']); if (!empty($coupon['discount_percentage'])) { $discountAmount = $item['price']->copy()->times($coupon['discount_percentage'] / 100); $this->orderObject->vattotal -= $item['price_supplement']->display * ($coupon['discount_percentage'] / 100); $this->orderObject->base_price->subtract($this->orderObject->price_net->copy()->times($coupon['discount_percentage'] / 100)); } else { if (!empty($coupon['discount_flat'])) { $discountAmount = Money::fromString($coupon['discount_flat']); } else { $discountAmount = Money::fromFloat(0); } } $discountAmount = Money::min($discountAmount, $item['price']); $this->orderObject->itemSubtotal->subtract($discountAmount); $this->orderObject->discount->add($discountAmount); $this->orderObject->discount_remainder->add($item['price']->copy()->subtract($discountAmount)); $this->orderObject->commissionable->subtract($commission); $this->orderObject->commissionSubtotal->subtract($commission); if ($commission->isGreaterThanZero()) { $this->orderObject->marketCommissionable->subtract($this->orderObject->price_net); if ($this->orderObject->in_market === TRUE) { $this->orderObject->presenterCommissionable->subtract($this->orderObject->price_net); } else { $this->orderObject->presenterCommissionable->subtract($commission->copy()->times($this->orderObject->payPegRate)); } } // added this make sure that the market_commissionable_total value is correct. // if it's not, the front end will allow too much ycash to be applied to an order // potentially allowing negative prs and commission calculations $order_presenter_id = Configure::read("order_presenter_id"); // if (empty($order_presenter_id)) // { $this->orderObject->marketCommissionable->subtract($this->orderObject->price_supplement); // } //No points for discounted items $this->orderObject->totalPoints -= $this->orderObject->points; $this->orderObject->discounts[$couponId] = array("name" => $coupon['name'], "amount" => $discountAmount); } } else { $commission = Money::fromFloat(0); } if (in_array($item['sku'], ProductGlobal::halfPriceExcluded()) || $item['item_type_id'] == Item::TYPE_CONVENTION_TICKET || $item['item_type_id'] == Item::TYPE_SUPPLIES || $item['item_type_id'] == Item::TYPE_SUPPLIES_SETS) { $hpDisabled = true; } else { $hpDisabled = false; } return array('hpDisabled' => $hpDisabled, 'commission' => $commission); }