public function testAddNoUser() { $this->assertEqual($this->ShoppingCart->addItem("US-1001-00", array("qty" => 1)), array("success" => true, "count" => 1)); $this->assertEqual($this->ShoppingCart->addItem("US-1012-00", array("qty" => 5, "US-1011-00" => array("skus" => array("US-1011-03" => 1, "US-1011-04" => 1, "US-1011-05" => 1, "US-1011-06" => 1)))), array("success" => true, "count" => 2)); $this->assertEqual($this->ShoppingCart->getCart(), array("total" => array("subtotal" => Money::fromFloat(274), "taxes" => Money::fromFloat(0), "shipping" => Money::fromFloat(0), "total" => Money::fromFloat(274), "commissionable_total" => Money::fromFloat(274), 'productcredits' => Money::fromFloat(0), 'charge' => Money::fromFloat(274), 'usedCoupons' => array(), 'totalItemCount' => 6, 'toFreeShipping' => Money::fromFloat(-174)), "0" => array("item_id" => '1', 'sku' => 'US-1001-00', "name" => "Presenter Starter Kit", "quantity" => 1, "price" => Money::fromFloat(99.0), "subtotal" => Money::fromFloat(99.0), "taxes" => Money::fromFloat(0), "originalsubtotal" => Money::fromFloat(99.0), "discount" => Money::fromFloat(0), "discounts" => array(), "shipping" => Money::fromFloat(10), "total" => Money::fromFloat(99.0), 'image' => array('name' => 'Main', 'thumb_path' => '/img/product_images/fake_thumb.jpg', 'file_path' => '/img/product_images/fake_main.jpg'), "included" => array(), 'options' => array()), "1" => array("item_id" => '3', 'sku' => 'US-1012-00', "name" => "Minerals Pigment Set", "quantity" => 5, "price" => Money::fromFloat(35.0), "subtotal" => Money::fromFloat(175), "taxes" => Money::fromFloat(0), "shipping" => Money::fromFloat(5.0), "total" => Money::fromFloat(175), "originalsubtotal" => Money::fromFloat(175), "discount" => Money::fromFloat(0), "discounts" => array(), 'image' => array('name' => 'Main', 'thumb_path' => '/img/product_images/US-1011-00-thumb.png', 'file_path' => '/img/product_images/US-1011-00.jpg'), 'included' => array(array('name' => 'Sassy', 'shortname' => 'Sassy', 'id' => '7', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-03', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-03-thumb.jpg', 'file_path' => '/img/product_images/US-1011-03.jpg')), array('name' => 'Regal', 'shortname' => 'Regal', 'id' => '8', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-04', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-04-thumb.jpg', 'file_path' => '/img/product_images/US-1011-04.jpg')), array('name' => 'Flirty', 'shortname' => 'Flirty', 'id' => '9', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-05', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-05-thumb.jpg', 'file_path' => '/img/product_images/US-1011-05.jpg')), array('name' => 'Playful', 'shortname' => 'Playful', 'id' => '10', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-06', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-06-thumb.jpg', 'file_path' => '/img/product_images/US-1011-06.jpg'))), 'options' => array('US-1011-00' => array('skus' => array('US-1011-03' => 1, 'US-1011-04' => 1, 'US-1011-05' => 1, 'US-1011-06' => 1)))))); $this->assertEqual($this->ShoppingCart->getCart("84003"), array("total" => array("subtotal" => Money::fromFloat(274), "taxes" => Money::fromFloat(18.5), "shipping" => Money::fromFloat(0), "total" => Money::fromFloat(292.5), "commissionable_total" => Money::fromFloat(274), 'productcredits' => Money::fromFloat(0), 'charge' => Money::fromFloat(292.5), 'usedCoupons' => array(), 'totalItemCount' => 6, 'toFreeShipping' => Money::fromFloat(-174)), "0" => array("item_id" => 1, 'sku' => 'US-1001-00', "name" => "Presenter Starter Kit", "quantity" => 1, "price" => Money::fromFloat(99.0), "subtotal" => Money::fromFloat(99.0), "taxes" => Money::fromFloat(6.68), "shipping" => Money::fromFloat(10), "originalsubtotal" => Money::fromFloat(99.0), "discount" => Money::fromFloat(0), "discounts" => array(), "total" => Money::fromFloat(105.68), 'image' => array('name' => 'Main', 'thumb_path' => '/img/product_images/fake_thumb.jpg', 'file_path' => '/img/product_images/fake_main.jpg'), "included" => array(), 'options' => array()), "1" => array("item_id" => 3, 'sku' => 'US-1012-00', "name" => "Minerals Pigment Set", "quantity" => 5, "price" => Money::fromFloat(35.0), "subtotal" => Money::fromFloat(175), "taxes" => Money::fromFloat(11.81), "shipping" => Money::fromFloat(5.0), "total" => Money::fromFloat(186.81), "originalsubtotal" => Money::fromFloat(175), "discount" => Money::fromFloat(0), "discounts" => array(), 'image' => array('name' => 'Main', 'thumb_path' => '/img/product_images/US-1011-00-thumb.png', 'file_path' => '/img/product_images/US-1011-00.jpg'), "included" => array(array('name' => 'Sassy', 'shortname' => 'Sassy', 'id' => '7', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-03', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-03-thumb.jpg', 'file_path' => '/img/product_images/US-1011-03.jpg')), array('name' => 'Regal', 'shortname' => 'Regal', 'id' => '8', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-04', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-04-thumb.jpg', 'file_path' => '/img/product_images/US-1011-04.jpg')), array('name' => 'Flirty', 'shortname' => 'Flirty', 'id' => '9', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-05', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-05-thumb.jpg', 'file_path' => '/img/product_images/US-1011-05.jpg')), array('name' => 'Playful', 'shortname' => 'Playful', 'id' => '10', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-06', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-06-thumb.jpg', 'file_path' => '/img/product_images/US-1011-06.jpg'))), 'options' => array('US-1011-00' => array('skus' => array('US-1011-03' => 1, 'US-1011-04' => 1, 'US-1011-05' => 1, 'US-1011-06' => 1)))))); }
public function orderCreate($country_id, $presenterId, $userId, $hostmarket_id, $partyId) { $address = array("first_name" => "testing", "last_name" => "last", "address1" => "Some address 1", "address2" => "Some address 2", "address3" => "Some address 3", "city" => "Awesome city", "state_id" => 20, "postal_code" => "84003", "email_address" => "*****@*****.**", "country_id" => $country_id); $promoterId = 2; //$presenterId = 141683; // from presenter , we get market_id for orders $items = array(array("sku" => "US-2005-00", "qty" => 1, options => array("US-1092-00" => array("skus" => array("US-1082-01" => 1, "US-1083-03" => 1))))); $coupons = array(); $productCredits = Money::fromFloat(0.0); //20.00//29.00//29.00//45.00//29.00//90.00//75.00//175.00//58.00 //$prices = $this->Order->getOrderCosts($address['postal_code'], $items,null, $coupons); $prices = $this->Order->getOrderCosts($address['postal_code'], $items, $productCredits, $coupons); //$prices = $this->getOrderCosts($address['country_id'], $items,null, $coupons); //echo "<pre>"; //print_r($prices);exit; $insert_order = TRUE; // $result = $this->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,null, $coupons,FALSE,$insert_order); $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address, Order::TYPE_PRODUCT, $productCredits, $coupons, FALSE); // $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,$productCredits, $coupons,FALSE);//$insert_order $orderId = $this->Order->id; debug($orderId); // debug($result); // exit; $orderPaymentResult = array("success" => false, "payments" => array(array('type' => 'creditcard', 'amount' => $prices['total']['total'], "transaction_id" => "Wohootest", "identifier" => "3123", 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'failed'))); $result = $this->Order->finalize($orderPaymentResult); debug($prices['total']['total']); $orderPaymentResult = array("success" => true, "payments" => array(array('type' => 'creditcard', 'transaction_id' => 'Wohootest', 'amount' => $prices['total']['total'], 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'success', "identifier" => "3123"))); $result = $this->Order->finalize($orderPaymentResult); return $orderId; }
public function testProcessOrderLedgerPayments() { PHPUnit_Framework_Error_Warning::$enabled = FALSE; $result = $this->Payment->processOrderPayments("Test Order #13123", array(array("type" => "ledger", "presenter_id" => 1, "user_id" => 1, "amount" => Money::fromFloat(60)), array("type" => "creditcard", "amount" => Money::fromFloat(30), "cardholder" => "Test wohoo", "billingzip" => "84003", "cardnum" => "4068758923310472", "carexp" => "12/2015", "cardcode" => "962"))); $this->assertTrue($result['success']); $this->assertTrue(!empty($result['payments'][0]['transaction_id']) && strlen($result['payments'][0]['transaction_id']) == 17); }
public function testProductCreditSubtractions() { $presenterId = 1; $userId = 1; $this->assertEqual($this->ProductCredit->balance($presenterId, $userId), Money::fromFloat(70)); $transactionId = $this->ProductCredit->authorize(ProductCredit::METHOD_MANUAL, ProductCredit::TYPE_PURCHASE, $presenterId, $userId, Money::fromFloat(20), "Steve", "Manual Subtraction"); $this->assertEqual($transactionId !== false, true); $productCredit = $this->ProductCredit->findById($transactionId); unset($productCredit['ProductCredit']['id']); unset($productCredit['ProductCredit']['modified']); unset($productCredit['ProductCredit']['created']); $this->assertArraysEqual($productCredit, array('ProductCredit' => array('user_id' => '1', 'presenter_id' => '1', 'product_credit_type_id' => '4', 'product_credit_entry_type_id' => '2', 'product_credit_status_type_id' => '1', 'entry_user' => 'Steve', 'reference_id' => 'Manual Subtraction', 'amount' => '-20.00'))); //Doesn't have enough money $this->assertEqual($this->ProductCredit->balance($presenterId, $userId), Money::fromFloat(50)); $result = $this->ProductCredit->authorize(ProductCredit::METHOD_MANUAL, ProductCredit::TYPE_PURCHASE, $presenterId, $userId, Money::fromFloat(90), "Steve", "Manual Subtraction"); $this->assertEqual($result, false); $this->assertEqual($this->ProductCredit->balance($presenterId, $userId), Money::fromFloat(50)); //Doesn't have enough money, but somehow hacked around it // now you can set your expectations here $this->ProductCreditBadBalance->expects($this->at(0))->method('balance')->will($this->returnValue(Money::fromFloat(30000))); $this->ProductCreditBadBalance->expects($this->at(1))->method('balance')->will($this->returnValue(Money::fromFloat(-200))); $result = $this->ProductCreditBadBalance->authorize(ProductCredit::METHOD_MANUAL, ProductCredit::TYPE_PURCHASE, $presenterId, $userId, Money::fromFloat(90), "Steve", "Manual Subtraction"); $this->assertEqual($result, false); $this->assertEqual($this->ProductCredit->balance($presenterId, $userId), Money::fromFloat(50)); $productCredit = $this->ProductCredit->find("first", array("order" => "id desc")); unset($productCredit['ProductCredit']['id']); unset($productCredit['ProductCredit']['modified']); unset($productCredit['ProductCredit']['created']); $this->assertArraysEqual($productCredit, array('ProductCredit' => array('user_id' => '1', 'presenter_id' => '1', 'product_credit_type_id' => '4', 'product_credit_entry_type_id' => '2', 'product_credit_status_type_id' => '3', 'entry_user' => 'Steve', 'reference_id' => 'Manual Subtraction', 'amount' => '-90.00'))); }
public function testRewardCalculation() { $rewards = $this->PartyReward->calculateRewards(Money::fromFloat(45)); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(45), "Free Product" => "0%", "Free Product Credits" => Money::fromFloat(0), "Half-Price Items" => 0)); $rewards = $this->PartyReward->calculateRewards(Money::fromFloat(200.21)); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(200.21), "Free Product" => "10%", "Free Product Credits" => Money::fromFloat(20.02), "Half-Price Items" => 1)); $rewards = $this->PartyReward->calculateRewards(Money::fromFloat(349.99)); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(349.99), "Free Product" => "10%", "Free Product Credits" => Money::fromFloat(35.0), "Half-Price Items" => 1)); $rewards = $this->PartyReward->calculateRewards(Money::fromFloat(350.0)); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(350.0), "Free Product" => "12%", "Free Product Credits" => Money::fromFloat(42.0), "Half-Price Items" => 2)); $rewards = $this->PartyReward->calculateRewards(Money::fromFloat(350.01)); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(350.01), "Free Product" => "12%", "Free Product Credits" => Money::fromFloat(42.0), "Half-Price Items" => 2)); $rewards = $this->PartyReward->calculateRewards(Money::fromFloat(999.99)); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(999.99), "Free Product" => "14%", "Free Product Credits" => Money::fromFloat(140.0), "Half-Price Items" => 3)); $rewards = $this->PartyReward->calculateRewards(Money::fromFloat(1000.0)); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(1000.0), "Free Product" => "16%", "Free Product Credits" => Money::fromFloat(160), "Half-Price Items" => 4)); $rewards = $this->PartyReward->calculateRewards(Money::fromFloat(8000.0)); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(8000.0), "Free Product" => "16%", "Free Product Credits" => Money::fromFloat(1280), "Half-Price Items" => 4)); }
public function calculateRewards(Money $amount, $points, $hostess_market_id) { $reward = $this->find("first", array("conditions" => array("points_min <=" => $points), "order" => "points_min desc")); // $excess = $amount->toFloat() - (float)$reward['PartyReward']['price_min']; // $range = (float)$reward['PartyReward']['price_max'] - (float)$reward['PartyReward']['price_min']; $excess = $points - (int) $reward['PartyReward']['points_min']; $range = (int) $reward['PartyReward']['points_max'] - (double) $reward['PartyReward']['points_min']; if ($range <= 0) { $ratio = "0"; } else { $ratio = round($excess / $range, 2) + (int) $reward['PartyReward']['half_price_coupons']; } $product_credit_percentage = (int) $reward['PartyReward']['product_credit_percentage'] / 100; $rewards = $this->calculateRewardPoints($points, $hostess_market_id, $product_credit_percentage); //Kudos Start //$kudosData = $this->Kudos->checkPartyPoints($points); //Kudos End return array("Order Total" => $amount, "Points Total" => $rewards['Party Points'], "Points Needed" => (int) $reward['PartyReward']['points_max'] - $points + 1, "Progress Ratio" => $ratio, "Reward Points" => $rewards['Reward Points'], "Reward Peg Rates" => $this->rewardPegRates, "Free Product" => $reward['PartyReward']['product_credit_percentage'] . "%", "Free Product Credits" => $rewards['Free Product Credits'], "Half-Price Items" => $reward['PartyReward']['half_price_coupons'], "free_product_credits" => Money::fromFloat($rewards['Free Product Credits']), "half_price_item" => $reward['PartyReward']['half_price_coupons']); }
public function testprices() { $result = $this->testAction('/Shoppingcart/prices', array('return' => 'vars')); // debug($result); unset($result['result']['total']['time']); $expected = array('code' => (int) 200, 'error' => false, 'result' => array('total' => array('subtotal' => Money::fromFloat(0.0), 'discounts' => array(), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(10.0), 'total' => Money::fromFloat(10.0), 'kudos_total' => Money::fromFloat(0.0), 'productcredits' => Money::fromFloat(0.0), 'commissionable' => Money::fromFloat(0.0), 'commissionable_total' => Money::fromFloat(0.0), 'charge' => Money::fromFloat(10.0), 'usedCoupons' => array(), 'points' => (int) 0, 'market_commissionable_total' => Money::fromFloat(0.0), 'market_commissionable' => Money::fromFloat(0.0), 'presenter_commissionable' => Money::fromFloat(0.0), 'appliedPoints' => (int) 0, 'negativePoints' => (int) 0, 'totalItemCount' => (int) 0, 'toFreeShipping' => Money::fromFloat(200.0), 'prop65_flag' => false, 'errors_type' => 'none', 'errors' => 'none', 'product_creditable' => Money::fromFloat(0.0), 'last_quote_date' => '2015-03-26', 'orderLimit' => Money::fromFloat(800.0), 'orderLimitUsed' => Money::fromFloat(0.0), 'orderLimitRemaining' => Money::fromFloat(800.0), 'orderLimitThrottleValue' => '36', 'orderLimitThrottlePeriod' => 'daily', 'rolling_used' => Money::fromFloat(0.0), 'rollingRemaining' => Money::fromFloat(800.0)))); /* $expected = array( 'code' => (int) 200, 'error' => false, 'result' => array( 'total' => array( 'subtotal' => Money::fromFloat(0.00), 'discounts' => array(), 'taxes' => Money::fromFloat(0.00), 'shipping' => Money::fromFloat(5.50), 'total' =>Money::fromFloat(5.50), 'productcredits' => Money::fromFloat(0.00), 'commissionable' =>Money::fromFloat(0.00), 'commissionable_total' => Money::fromFloat(0.00), 'charge' => Money::fromFloat(5.50), 'usedCoupons' => array(), 'points' => (int) 0, 'market_commissionable_total' => Money::fromFloat(0.00), 'market_commissionable' => Money::fromFloat(0.00), 'presenter_commissionable' => Money::fromFloat(0.00), 'appliedPoints' => (int) 0, 'negativePoints' => (int) 0, 'totalItemCount' => (int) 0, 'toFreeShipping' => Money::fromFloat(100.00), 'prop65_flag' => false, 'errors_type' => 'none', 'errors' => 'none', 'product_creditable' => Money::fromFloat(0.00), 'last_quote_date' => '2015-03-13', 'time' => date('Y-m-d H:i:s') ) ) ); */ $this->assertEquals($result, $expected); }
public function testDonationWithHalfOrder() { $nonce = Braintree_Test_Nonces::$transactable; $data = array('sponsor_id' => 984, "user_id" => "5824", 'sponsorSearch' => '', 'market_id' => 1, 'first_name' => 'prachita', 'last_name' => '00test', 'email' => '*****@*****.**', 'address1' => '1825 W Research Way', 'address2' => '', 'address3' => '', 'city' => 'SALT LAKE CITY', 'county' => '', 'state' => 'Indiana', 'postal_code' => '84006', 'qas_state' => 'Indiana', 'qas_country' => 1, 'sameAsShipping' => 'on', 'billing_market_id' => '1', 'billingEmail' => '', 'billingAddress1' => '', 'billingAddress2' => '', 'billingCity' => '', 'billingState' => '', 'billingZip' => '', 'billingCardholderFirstName' => 'test', 'billingCardholderLastName' => 'test1', 'cardNum' => '4111111111111111', 'cardCode' => '115', 'cardExpMonth' => '07', 'cardExpYear' => '2019', 'items' => array(array("sku" => "US-11901-01", "qty" => 1, "coupons" => array("1" => array("discount_percentage" => 50, "discount_flat" => Money::fromFloat(0), "name" => "Half Priced Item")))), "party_id" => "Select the party", "productcredits" => 0, "commissionable_total" => 39.0, "processor" => 2, "hasdonation" => true); $data1 = array("sku" => "US-11901-01", "qty" => 1); //[coupons][]:832447 $clear1 = $this->testAction('/shoppingcart/clear', array('return' => 'vars')); $data2 = array("sku" => "US-1017-00", "qty" => 1); $adding = $this->testAction('shoppingcart/add', array('data' => $data1, 'method' => 'post', 'return' => 'vars')); // $adding = $this->testAction('shoppingcart/add',array('data' => $data2, 'method' => 'post','return' => 'vars')); $actual1 = $this->testAction('/shoppingcart/purchase', array('data' => $data, 'method' => 'post', 'return' => 'vars')); $orderId = $actual1['result']['id']; $actualdata = $this->Order->find('first', array('conditions' => array('id' => $orderId))); // debug($actualdata); // debug($actual1); unset($actualdata['Order']['date_started']); unset($actualdata['Order']['date_completed']); unset($actualdata['Order']['_auditdate']); $expected1 = array('Order' => array('id' => $orderId, 'user_id' => '5824', 'presenter_id' => '984', 'promoter_id' => '0', 'party_id' => '0', 'order_type_id' => '3', 'order_status_id' => '3', 'secondary_order_status_id' => null, 'market_id' => '1', 'order_market_id' => '1', 'subtotal' => '19.50', 'taxtotal' => '0.00', 'shippingtotal' => '5.50', 'discount' => '0.00', 'commissionable_total' => '0.00', 'market_commissionable' => '0.00', 'presenter_commissionable' => '0.00', 'grand_total' => '25.00', 'point_total' => '0.00', 'donation' => '0.00', 'ip_address' => '2130706433', 'itemCount' => '1')); $this->assertEqual($actualdata, $expected1); }
public function testycash() { /* $yCashCreated = $this->ProductCredit->saveCreate(array( "presenter_id" => 203778, "market_id"=>1, "product_credit_type_id"=>4, "coupon_id"=>1, "discount_percentage"=>50, //"user_id" => 2, "reference_id" => 2, "user_visible" => 0, "start_date"=>date('Y/m/d H:i:s'), "end_date" => "0000-00-00" )); // $yCashCreated = $this->_refundYCash($value['transactionid']); } */ $yCashCreated = $this->ProductCredit->saveCreate(array("market_id" => 2, "user_id" => 2082448, "presenter_id" => 203775, "product_credit_type_id" => 4, "product_credit_entry_type_id" => 2, "product_credit_status_type_id" => 1, "amount" => Money::fromFloat(200.0), "reference_id" => "test")); }
public function main() { if (empty($this->args[0])) { $today = strtotime(date("Y-m-d 00:00:00")); } else { $today = strtotime(date("Y-m-d 00:00:00", strtotime($this->args[0]))); } /*** * BIRTHDAY CASH */ $result = $this->Presenter->find("all", array("contain" => array("User" => array("fields" => array("id", "date_of_birth"))), "conditions" => array("month(User.date_of_birth) = " . date("m", $today), "day(User.date_of_birth) = " . date("d", $today), "Presenter.presenter_status_id" => PresenterStatus::COMPLETE))); foreach ($result as $presenter) { $birthday = date("Y-m-d", $today); if (!$this->Presenter->User->ProductCredit->checkExists(ProductCredit::TYPE_BIRTHDAY, $presenter['User']['id'], $birthday)) { // market touch point $trait = $this->TraitCountry->getTrait($presenter['Presenter']['market_id'], 'birthday_cash'); $amount = !empty($trait) ? $trait : $this->TraitCountry->getTrait(1, 'birthday_cash'); $this->Presenter->User->ProductCredit->credit(ProductCredit::METHOD_SYSTEM, ProductCredit::TYPE_BIRTHDAY, $presenter['Presenter']['market_id'], $presenter['Presenter']['id'], $presenter['User']['id'], Money::fromFloat($amount), "BirthdayCashShell", $birthday); } } }
public function testFinalizeParty() { $presenterId = 1; $userId = 3; $rewardAmount = Money::fromFloat(52.2); $this->Party->id = 3; $rewards = $this->Party->calculateRewards(); $this->assertArraysEqual($rewards, array("Order Total" => Money::fromFloat(435), "Free Product" => "12%", "Progress Ratio" => 2.57, "Free Product Credits" => $rewardAmount, "Half-Price Items" => 2)); $oldBalance = $this->Party->ProductCredit->balance($presenterId, $userId); $oldCoupons = $this->User->CouponPresenterUser->availableHalfOffCoupons($presenterId, $userId); $this->Party->finalize(); $newBalance = $this->Party->ProductCredit->balance($presenterId, $userId); $newCoupons = $this->User->CouponPresenterUser->availableHalfOffCoupons($presenterId, $userId); $this->assertEqual($newBalance, $rewardAmount->copy()->add($oldBalance)); $this->assertEqual(count($newCoupons), count($oldCoupons) + $rewards['Half-Price Items']); $this->Party->id = 1; $fields = $this->Party->read(array("presenter_id", "hostess_id")); $oldBalance = $this->Party->ProductCredit->balance($presenterId, $userId); $oldCoupons = $this->User->CouponPresenterUser->availableHalfOffCoupons($presenterId, $userId); $this->Party->finalize(); $newBalance = $this->Party->ProductCredit->balance($presenterId, $userId); $this->assertEqual($newBalance, $oldBalance); $this->assertEqual(count($newCoupons), count($oldCoupons)); }
public function testCantoUkHalfpriceWithcashOrder() { if (isset($_REQUEST["shipment_country_id"])) { $country_id = $_REQUEST["shipment_country_id"]; } else { $country_id = 5; } $marketId = 5; $commission_rate = 0.25; //0.20;//0.25; $presenterMarketId = 2; if (isset($_REQUEST["pid"])) { $presenterId = $_REQUEST["pid"]; } else { $presenterId = 202807; //203796;//203778;//201406;//203776;//203663;//203776;//203778;//203775;//203778; } //debug($presenterId."".$country_id); $userId = 193541; //1091475;//2082454;//1610480;//2003031;//1926829;//2003031;//2082454;//4;//2082448;//2082454; $partyId = 223; //213; $productCredits = Money::fromFloat(29.0); //29.00 $address = array("first_name" => "testing", "last_name" => "last", "address1" => "Some address 1", "address2" => "Some address 2", "address3" => "Some address 3", "city" => "Awesome city", "state_id" => 20, "postal_code" => "84003", "email_address" => "*****@*****.**", "country_id" => $country_id); $promoterId = 2; //$presenterId = 141683; // from presenter , we get market_id for orders $items = array(array("sku" => "US-1017-00", "qty" => 4, "coupons" => array("1" => array("discount_percentage" => 50, "discount_flat" => Money::fromFloat(0), "name" => "Half Priced Item"), "2" => array("discount_percentage" => 50, "discount_flat" => Money::fromFloat(0), "name" => "Half Priced Item")))); $coupons = array(); $prices = $this->Order->getOrderCosts($address['postal_code'], $items, $productCredits, $coupons); //$prices = $this->getOrderCosts($address['country_id'], $items,null, $coupons); //echo "<pre>"; //print_r($prices);exit; $insert_order = TRUE; // $result = $this->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,null, $coupons,FALSE,$insert_order); $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address, Order::TYPE_PRODUCT, $productCredits, $coupons, FALSE); // $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,$productCredits, $coupons,FALSE);//$insert_order $orderId = $this->Order->id; // debug($orderId); // debug($result); // exit; $orderPaymentResult = array("success" => false, "payments" => array(array('type' => 'creditcard', 'amount' => $prices['total']['total'], "transaction_id" => "Wohootest", "identifier" => "3123", 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'failed'))); $result = $this->Order->finalize($orderPaymentResult); // debug($prices['total']['total']); $orderPaymentResult = array("success" => true, "payments" => array(array('type' => 'creditcard', 'transaction_id' => 'Wohootest', 'amount' => $prices['total']['total'], 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'success', "identifier" => "3123"))); $result = $this->Order->finalize($orderPaymentResult); // $presenterId = 154305; // $userId = 1477959; // $orderId = 2000149; $marketcomission = $this->OrderCommission->calculateCommission($orderId, $marketId, $presenterMarketId); // $marketcomission=$marketCommissionable*(5/6); $RoyaltyAmount = $this->OrderCommission->getRoyaltiesEarnedByOrderId($orderId); $expected_value = round($marketcomission * $commission_rate, 2); // $expected_value = '0.00'; $this->assertEqual($RoyaltyAmount, $expected_value); }
public function listRetailCommissions($status = self::STATUS_UNPAID, $limit = null, $threeHourWindow = true, $thread = NULL) { App::import('model', 'Market'); $status = strtolower($status); $order = "date_earned asc"; if ($status == "paid") { $conditions = array("RoyaltiesEarned.date_paid is not null"); } else { if ($status == "failed") { $conditions = array("RoyaltiesEarned.date_paid is null", "RoyaltiesEarned.date_attempted is not null"); } else { $conditions = array("RoyaltiesEarned.date_paid is null", "RoyaltiesEarned.date_attempted is null"); if ($threeHourWindow === true) { $conditions[] = "RoyaltiesEarned.date_earned < DATE_SUB('" . date("Y-m-d H:i:s") . "', INTERVAL 3 HOUR)"; } } } $conditions["RoyaltiesEarned.royalty_type_id"] = self::TYPE_RETAIL; $conditions["RoyaltiesEarned.royalty_status_id"] = RoyaltiesEarned::STATUS_APPROVED; if ($thread !== NULL) { $conditions["SUBSTRING(RoyaltiesEarned.presenter_id, -1)"] = $thread; } $commissions = $this->find("all", array("contain" => array("Presenter" => array("User" => array("RoyaltiesEmail")), "Order"), "fields" => array("*", "(select sum(amount) from royalties_earned as re where re.presenter_id = RoyaltiesEarned.presenter_id) as totalRoyalties"), "conditions" => $conditions, "order" => $order, "limit" => $limit)); $outCommissions = array(); foreach ($commissions as $commission) { $cardLimit = Money::fromFloat($commission['RoyaltiesEarned']['market_id'] == Market::MARKET_MEXICO ? 750 : 50); //get currency $market_id = $commission['RoyaltiesEarned']['market_id']; $currency = $this->Market->getCurrencyType($market_id); if ((int) $market_id == Market::MARKET_MEXICO) { if (!$this->payMexicoCommissions($commission['Presenter']['id'])) { $this->clear(); $this->id = $commission['RoyaltiesEarned']['id']; $this->saveField("royalty_status_id", RoyaltiesEarned::STATUS_PRESENTER_NOT_VERIFIED); continue; } } else { if ((int) $market_id == Market::MARKET_FRANCE) { if (!$this->payFranceCommissions($commission['Presenter']['id'])) { $this->clear(); $this->id = $commission['RoyaltiesEarned']['id']; $this->saveField("royalty_status_id", RoyaltiesEarned::STATUS_PRESENTER_NOT_VERIFIED); continue; } } } $outCommissions[] = array("id" => $commission['RoyaltiesEarned']['id'], "presenter_sequence_id" => $commission['Presenter']['presenter_sequence_id'], "presenter_id" => $commission['Presenter']['id'], "name" => $commission['Presenter']['User']['first_name'] . " " . $commission['Presenter']['User']['last_name'], "first_name" => $commission['Presenter']['User']['first_name'], "payquickeremail" => $commission['Presenter']['User']['RoyaltiesEmail']['email'], "type" => $commission['RoyaltiesEarned']['royalty_type_id'] == RoyaltiesEarned::TYPE_RETAIL ? 'retail' : 'other', "amount" => $commission['RoyaltiesEarned']['amount'], "withholding" => $commission['RoyaltiesEarned']['withholding'], "market_id" => $commission['RoyaltiesEarned']['market_id'], "currency" => $currency, "order_percentage" => $commission['RoyaltiesEarned']['order_percentage'], "order_id" => $commission['RoyaltiesEarned']['order_id'], "order_commissionable" => $commission['Order']['commissionable_total'], "order_subtotal" => $commission['Order']['subtotal'], "date_earned" => $commission['RoyaltiesEarned']['date_earned'], "date_attempted" => $commission['RoyaltiesEarned']['date_attempted'], "total_royalties" => (string) Money::fromFloat($commission[0]['totalRoyalties']), "forceCard" => Money::fromFloat($commission[0]['totalRoyalties'])->isGreaterThan($cardLimit) ? 'true' : 'false'); } return $outCommissions; }
public function testPencilSet15() { $countryId = '1'; $presenterId = '203720'; $userId = '1101371'; $hostMarketId = '1'; $partyId = '213'; $items = array(array("sku" => "US-32101-03", "qty" => 1)); $amountadjust = '0.00'; $resulto = $this->placeOrder($countryId, $presenterId, $userId, $hostMarketId, $partyId, $items, $amountadjust); $orderId = $resulto['orderId']; unset($resulto['orderId']); // debug($resulto); $expected = array((int) 0 => array('item_id' => '354', 'image' => array('name' => 'Moodstruck Precision Pencil Set Box Set of 15', 'thumb_path' => '/en_US/img/product_images/US-32101-03-thumb.jpg', 'file_path' => '/en_US/img/product_images/US-32101-03.jpg'), 'sku' => 'US-32101-03', 'name' => 'Moodstruck Precision Pencil Set Box Set of 15', 'dailyspecial' => false, 'backordered' => false, 'childBackordered' => false, 'item_availability' => array('id' => '469', 'item_id' => '354', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'backorder_message' => 'Due to overwhelming popularity, our Moodstruck Precision Pencil Set Box Set of 15 is currently on back order.', 'backorder_title' => 'This set is temporarily on back order', 'type_id' => '3', 'quantity' => (int) 1, 'price' => Money::fromFloat(165.0), 'points' => (int) 1650, 'commission' => Money::fromFloat(165.0), 'subtotal' => Money::fromFloat(165.0), 'commissionSubtotal' => Money::fromFloat(165.0), 'originalsubtotal' => Money::fromFloat(165.0), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(5.5), 'discount' => Money::fromFloat(0.0), 'discounts' => array(), 'kudosItem' => false, 'total' => Money::fromFloat(165.0), 'included' => array((int) 0 => array('name' => 'Moodstruck Precision Pencils - for Lips - Perky', 'shortname' => 'Perky', 'id' => '330', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12101-01', 'item_availability' => array('id' => '445', 'item_id' => '330', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Perky', 'thumb_path' => '/en_US//img/product_images/US-12101-01-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12101-01.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Lips'), (int) 1 => array('name' => 'Moodstruck Precision Pencils - for Lips - Pompous', 'shortname' => 'Pompous', 'id' => '331', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12101-02', 'item_availability' => array('id' => '446', 'item_id' => '331', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Pompous', 'thumb_path' => '/en_US//img/product_images/US-12101-02-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12101-02.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Lips'), (int) 2 => array('name' => 'Moodstruck Precision Pencils - for Lips - Posh', 'shortname' => 'Posh', 'id' => '332', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12101-03', 'item_availability' => array('id' => '447', 'item_id' => '332', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Posh', 'thumb_path' => '/en_US//img/product_images/US-12101-03-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12101-03.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Lips'), (int) 3 => array('name' => 'Moodstruck Precision Pencils - for Lips - Pouty', 'shortname' => 'Pouty', 'id' => '333', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12101-04', 'item_availability' => array('id' => '448', 'item_id' => '333', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Pouty', 'thumb_path' => '/en_US//img/product_images/US-12101-04-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12101-04.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Lips'), (int) 4 => array('name' => 'Moodstruck Precision Pencils - for Lips - Primal', 'shortname' => 'Primal', 'id' => '334', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12101-05', 'item_availability' => array('id' => '449', 'item_id' => '334', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Primal', 'thumb_path' => '/en_US//img/product_images/US-12101-05-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12101-05.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Lips'), (int) 5 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Passionate', 'shortname' => 'Passionate', 'id' => '335', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-01', 'item_availability' => array('id' => '450', 'item_id' => '335', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Passionate', 'thumb_path' => '/en_US//img/product_images/US-12102-01-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-01.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 6 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Perfect', 'shortname' => 'Perfect', 'id' => '336', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-02', 'item_availability' => array('id' => '451', 'item_id' => '336', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Perfect', 'thumb_path' => '/en_US//img/product_images/US-12102-02-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-02.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 7 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Polished', 'shortname' => 'Polished', 'id' => '337', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-03', 'item_availability' => array('id' => '452', 'item_id' => '337', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Polished', 'thumb_path' => '/en_US//img/product_images/US-12102-03-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-03.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 8 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Precarious', 'shortname' => 'Precarious', 'id' => '338', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-04', 'item_availability' => array('id' => '453', 'item_id' => '338', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Precarious', 'thumb_path' => '/en_US//img/product_images/US-12102-04-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-04.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 9 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Precious', 'shortname' => 'Precious', 'id' => '339', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-05', 'item_availability' => array('id' => '454', 'item_id' => '339', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Precious', 'thumb_path' => '/en_US//img/product_images/US-12102-05-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-05.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 10 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Presumptuous', 'shortname' => 'Presumptuous', 'id' => '340', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-06', 'item_availability' => array('id' => '455', 'item_id' => '340', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Presumptuous', 'thumb_path' => '/en_US//img/product_images/US-12102-06-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-06.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 11 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Prim', 'shortname' => 'Prim', 'id' => '341', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-07', 'item_availability' => array('id' => '456', 'item_id' => '341', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Prim', 'thumb_path' => '/en_US//img/product_images/US-12102-07-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-07.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 12 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Pristine', 'shortname' => 'Pristine', 'id' => '342', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-08', 'item_availability' => array('id' => '457', 'item_id' => '342', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Pristine', 'thumb_path' => '/en_US//img/product_images/US-12102-08-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-08.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 13 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Proper', 'shortname' => 'Proper', 'id' => '343', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-09', 'item_availability' => array('id' => '458', 'item_id' => '343', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Proper', 'thumb_path' => '/en_US//img/product_images/US-12102-09-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-09.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 14 => array('name' => 'Moodstruck Precision Pencils - for Eyes - Prosperous', 'shortname' => 'Prosperous', 'id' => '344', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12102-10', 'item_availability' => array('id' => '459', 'item_id' => '344', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Prosperous', 'thumb_path' => '/en_US//img/product_images/US-12102-10-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-12102-10.jpg'), 'tag' => 'Moodstruck Precision Pencils - for Eyes'), (int) 15 => array('name' => 'Pencil Sharpener', 'shortname' => 'Precision Pencil Sharpener', 'id' => '356', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-53001-01', 'item_availability' => array('id' => '471', 'item_id' => '356', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Precision Pencil Sharpener', 'thumb_path' => '/en_US/img/product_images/US-53001-01-thumb.jpg', 'file_path' => '/en_US/img/product_images/US-53001-01.jpg'), 'tag' => '')), 'options' => array(), 'prop65_flag' => '0'), 'total' => array('subtotal' => Money::fromFloat(165.0), 'discounts' => array(), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(0.0), 'total' => Money::fromFloat(165.0), 'productcredits' => Money::fromFloat(0.0), 'commissionable' => Money::fromFloat(165.0), 'commissionable_total' => Money::fromFloat(165.0), 'charge' => Money::fromFloat(165.0), 'usedCoupons' => array(), 'points' => (int) 1650, 'market_commissionable_total' => Money::fromFloat(165.0), 'market_commissionable' => Money::fromFloat(165.0), 'presenter_commissionable' => Money::fromFloat(165.0), 'appliedPoints' => (double) 1650, 'negativePoints' => (double) 0, 'totalItemCount' => (int) 1, 'toFreeShipping' => Money::fromFloat(-65.0), 'prop65_flag' => false, 'errors_type' => 'none', 'errors' => 'none')); //array(); $this->assertEqual($resulto, $expected); }
/** * Use this to calculate a value to be decremented from promo items due to ycash and HPI usage. * * If you change this function to match a kudo promo, save the existing code in the wiki with a * description so that it can be reused in the future * */ private function _checkPromoAdjustments($items, $ycash = null, $qualifying_items = array()) { //load the item model to get the price info on items App::import("Model", "Item"); $this->Item = new Item(); //get the productcredits $trigger_item = $this->Item->detailsBySku('US-1051-00'); $trigger_item_price = (double) $trigger_item['price']; //$trigger_item = $this->Item->detailsBySku($qualifying_items); //get additional skus (sets, combos, etc) of qualifying items if applicable //Hard code collections since I am short on time $collections = array("US-41011-01", "US-41021-01", "US-41031-01", "US-41041-01", "US-41051-01", "US-41061-01", "US-91201-01"); //to keep track of HPI in case of no ycash $total_qualifying_items = 0; $hpi_qty = 0; $count = 0; //contains the price value of trigger items in cart $qualifying_items_value = Money::fromFloat(0); //contains the price value of the non trigger items in the cart $total_adjusted_item_value = Money::fromFloat(0); $product_credits = Money::fromPennies($ycash); foreach ($items as $value) { $item_detail = $this->Item->detailsBySku($value['sku']); $price = $item_detail['price']; $coupons = (int) count(array_unique($value['coupons'])); $qty = (int) $value['qty']; if (in_array($value['sku'], $qualifying_items)) { $count += $qty; $floor = $qty - $coupons; $total_qualifying_items += $floor > 0 ? $floor : 0; $hpi_qty += $coupons; $iteration_value = Money::fromFloat($trigger_item_price)->times($qty - $coupons); $qualifying_items_value->add($iteration_value); } //for collections containing trigger item, make the min allowed non coupon value equal to the trigger item price if (in_array($value['sku'], $qualifying_items) && in_array($value['sku'], $collections)) { $total_adjusted_item_value->add(Money::fromFloat($price)->times($qty)); //reduce amount by items with HPI applied $total_adjusted_item_value->subtract(Money::fromFloat($price)->times($coupons)); } else { $total_adjusted_item_value->add(Money::fromFloat($price)->times($qty)); //reduce amount by items with HPI applied $total_adjusted_item_value->subtract(Money::fromFloat($price)->times($coupons)); } } $commissionable = $total_adjusted_item_value->copy()->subtract($product_credits); if ($commissionable->amount > 0 && $ycash->amount > 0) { //don't want to divide by 0 $divisor = $trigger_item_price == 0 ? 1 : $trigger_item_price * 100; $qualified_promo_qty = floor(($commissionable->amount - $ycash->amount) / $divisor); // $qualified_promo_qty = "($commissionable->amount / 100) / $divisor)"; return $qualified_promo_qty; } else { return $total_qualifying_items; } }
/** * Check promo adjustments and return qty of promo items * @param $items * @param $credits * @param $qualifying_items * @return int */ private function checkPromoAdjustments($items, $credits, $qualifying_items, $promo, $market_id) { $this->Item = new Item(); $this->ItemAvailabilityTimes = new ItemAvailabilityTimes(); $qualifying_items_value = Money::fromFloat(0); $non_qualifying_value = Money::fromFloat(0); $product_credits = Money::fromPennies($credits); $prices = []; $count = 0; $total_qualifying_items = 0; $hpi_qty = 0; $promo_iat = $this->ItemAvailabilityTimes->find('first', array('fields' => array('ItemAvailabilityTimes.item_availability_id'), 'joins' => array(array('table' => 'items', 'alias' => 'i', 'type' => 'INNER', 'foreignKey' => false, 'conditions' => array('ItemAvailabilityTimes.item_id = i.id', 'ItemAvailabilityTimes.start_date <=' => date("Y-m-d H:i:s"), 'OR' => array('ItemAvailabilityTimes.end_date >' => date("Y-m-d H:i:s"), 'ItemAvailabilityTimes.end_date' => NULL), 'i.sku' => $promo['reward_sku'])), array('table' => 'trait_countries', 'alias' => 'tc', 'type' => 'INNER', 'foreignKey' => false, 'conditions' => array('tc.name' => 'ns_warehouse', 'ItemAvailabilityTimes.ns_warehouse_id = tc.value', 'tc.reference_id' => $market_id))))); if (!empty($promo_iat['ItemAvailabilityTimes']['item_availability_id']) && in_array($promo_iat['ItemAvailabilityTimes']['item_availability_id'], [2, 3, 6, 8])) { // 2 = Sell remaining // 3 = Sell endless // 6 = Backorder Individual // 8 = Backorder All foreach ($items as $value) { // Database item $item_detail = $this->Item->detailsBySku($value['sku']); // Values $price = $item_detail['price']; $qty = (int) $value['qty']; $coupons = (int) count(array_unique($value['coupons'])); $count += $qty; $hpi_qty += $coupons; $type = $item_detail['type']; if ($promo['reward_type'] == 1 || $promo['reward_type'] == 2) { //BuyXgetY and hidden $floor = $qty - $coupons; if (in_array($value['sku'], $qualifying_items)) { for ($i = 0; $i < $floor; $i++) { $prices[] = $price; } $total_qualifying_items += $floor > 0 ? $floor : 0; $qualifying_items_value->add(Money::fromFloat($price)->times($floor)); } else { $non_qualifying_value->add(Money::fromFloat($price)->times($floor)); } } else { if ($promo['reward_type'] == 3) { //SpendXgetY if (!in_array($type, array(Item::TYPE_SUPPLIES, Item::TYPE_SUPPLIES_SETS, Item::TYPE_PRESENTER_KIT))) { $floor = (double) $qty - (double) $coupons / 2.0; $non_qualifying_value->add(Money::fromFloat($price)->times($floor)); } } } } if ($promo['reward_type'] == 1 || $promo['reward_type'] == 2) { //BuyXgetY and hidden // Sort by highest price rsort($prices); // Get yCash after other items if ($non_qualifying_value->isEqualOrGreaterThan($product_credits)) { $after_cash = Money::fromFloat(0); } else { $after_cash = $product_credits->copy()->subtract($non_qualifying_value); } if ($qualifying_items_value->amount > 0 && $after_cash->amount > 0) { return $this->getHighestQty($prices, $after_cash->amount); } else { return $total_qualifying_items; } } else { if ($promo['reward_type'] == 3) { //SpendXgetY $cart_amount = $non_qualifying_value->amount - $credits; $this->PromotionalSpendingAmount = new PromotionalSpendingAmount(); $spending_data = $this->PromotionalSpendingAmount->find('first', ['conditions' => ['promotional_product_id' => $promo['id'], 'market_id' => $market_id]]); $spending_amount = $spending_data['PromotionalSpendingAmount']['spending_amount']; if ($cart_amount >= $spending_amount) { return $promo['qty']; } else { return 0; } } } } //if the promos item_availability_time is not 2,3,6,8 then just return 0 //also a default return 0 return 0; }
public function ycashSubtract($presenter_id, $user_id, $market_id) { //$ycash_amount = Money::fromFloat(20); $ycash_amount = Money::fromFloat($this->request->data['ycash_amount']); $result = $this->ProductCredit->authorize(ProductCredit::METHOD_MANUAL, ProductCredit::TYPE_PURCHASE, $market_id, $presenter_id, $user_id, $ycash_amount, "Steve", "Manual Subtraction"); $this->sendSuccess($result); }
public function testCollectionFourYcash() { $data1 = array('sku' => 'US-42011-01', 'options' => array('qty' => 4, "US-22301-00" => array("skus" => array("US-12301-03" => 1, "US-12301-0" => 1)), "US-21801-00" => array("skus" => array("US-11801-04" => 1, "US-11801-10" => 1)), "US-22100-00" => array("skus" => array("US-12102-04" => 2)))); $data2 = array("market_id" => 1, "productcredits" => 350.0); $clear1 = $this->testAction('/shoppingcart/clear', array('return' => 'vars')); $adding = $this->testAction('shoppingcart/add', array('data' => $data1, 'method' => 'post', 'return' => 'vars')); $CartItems = $this->testAction('/shoppingcart/view', array('method' => 'post', 'data' => $data2, 'return' => 'vars')); $result = array('code' => (int) 200, 'error' => false, 'result' => array((int) 0 => array('item_id' => '513', 'image' => array('name' => null, 'thumb_path' => null, 'file_path' => null), 'sku' => 'US-42011-01', 'name' => null, 'dailyspecial' => false, 'backordered' => false, 'childBackordered' => false, 'item_availability' => array('id' => '700', 'item_id' => '548', 'item_availability_id' => '3', 'start_date' => '2015-04-26 22:46:42', 'end_date' => null), 'backorder_message' => 'Due to overwhelming popularity, individual orders of Three Little Words necklace are on temporary back order. Orders for this item can still be placed. Any other items ordered will ship immediately, with back ordered items shipping separately on a first come, first serve basis.', 'backorder_title' => 'This item is temporarily on back order', 'type_id' => '4', 'quantity' => (int) 4, 'price' => Money::fromFloat(99.0), 'points' => (int) 3960, 'commission' => Money::fromFloat(99.0), 'subtotal' => Money::fromFloat(396.0), 'commissionSubtotal' => Money::fromFloat(396.0), 'originalsubtotal' => Money::fromFloat(396.0), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(5.5), 'discount' => Money::fromFloat(0.0), 'discounts' => array(), 'kudosItem' => false, 'hpDisabled' => false, 'total' => Money::fromFloat(396.0), 'included' => array(), 'options' => array('US-22301-00' => array('skus' => array('US-12301-03' => (int) 1, 'US-12301-0' => (int) 1)), 'US-21801-00' => array('skus' => array('US-11801-04' => (int) 1, 'US-11801-10' => (int) 1)), 'US-22100-00' => array('skus' => array('US-12102-04' => (int) 2))), 'prop65_flag' => null), 'total' => array('subtotal' => Money::fromFloat(396.0), 'discounts' => array(), 'shipping' => Money::fromFloat(0.0), 'total' => Money::fromFloat(396.0), 'kudos_total' => Money::fromFloat(396.0), 'productcredits' => Money::fromFloat(0.0), 'commissionable' => Money::fromFloat(396.0), 'commissionable_total' => Money::fromFloat(396.0), 'charge' => Money::fromFloat(396.0), 'usedCoupons' => array(), 'points' => (double) 3960, 'market_commissionable_total' => Money::fromFloat(396.0), 'market_commissionable' => Money::fromFloat(396.0), 'presenter_commissionable' => Money::fromFloat(396.0), 'appliedPoints' => (double) 3960, 'negativePoints' => (double) 0, 'totalItemCount' => (double) 7, 'toFreeShipping' => Money::fromFloat(-396.0), 'prop65_flag' => false, 'freeCatalog' => false, 'toFreeCatalog' => '50.00', 'errors_type' => 'none', 'errors' => 'none', 'taxes' => Money::fromFloat(0.0)))); $this->assertEquals($result, $CartItems); // debug($adding); // exit; }
public function orderCreate($country_id, $presenterId, $userId, $hostmarket_id, $partyId) { Configure::write("market_id", (int) $country_id); $qty = 1; if ($country_id == 1) { $postal_code = "20350-1000"; // $qty = 8; } else { if ($country_id == 2) { $postal_code = "K1A 0B1"; } else { if ($country_id == 3) { $postal_code = "0872"; } else { if ($country_id == 4) { $postal_code = "6000"; } else { if ($country_id == 5) { // $qty = 3; $postal_code = "NN8 4TH"; } else { if ($country_id == 6) { $country_id = 9; $postal_code = "54040"; } else { echo "I am from else block"; exit; } } } } } } // debug($postal_code); $address = array("first_name" => "testing", "last_name" => "last", "address1" => "Some address 1", "address2" => "Some address 2", "address3" => "Some address 3", "city" => "Awesome city", "state_id" => 20, "postal_code" => $postal_code, "email_address" => "*****@*****.**", "country_id" => $country_id); $promoterId = 2; //$presenterId = 141683; // from presenter , we get market_id for orders /* //power kit sku:US-42011-01 options[qty]:1 options[US-22301-00][skus][US-12301-02]:1 options[US-22301-00][skus][US-12301-08]:1 options[US-21801-00][skus][US-11801-08]:1 options[US-21801-00][skus][US-11801-10]:1 options[US-22100-00][skus][US-12102-05]:1 options[US-22100-00][skus][US-12102-09]:1 //shoppers kit sku:US-42031-01 options[qty]:1 options[US-21000-00][skus][US-11001-01]:1 options[US-21000-00][skus][US-11001-08]:1 options[US-22100-00][skus][US-12101-03]:1 options[US-22100-00][skus][US-12101-04]:1 options[US-21400-00][skus][US-11401-07]:1 options[US-22401-00][skus][US-12401-03]:1 options[US-22301-00][skus][US-12301-07]:1 //About Face sku:US-42041-01 options[qty]:1 options[US-21600-00][skus][US-11601-01]:1 options[US-21200-00][skus][US-11201-04]:1 options[US-21300-00][skus][US-11301-04]:1 //All eyes on you sku:US-42051-01 options[qty]:1 options[US-21000-00][skus][US-11001-01]:1 options[US-21000-00][skus][US-11001-16]:1 options[US-22100-00][skus][US-12101-03]:1 options[US-22100-00][skus][US-12101-05]:1 options[US-22501-00][skus][US-12501-01]:1 //Radient beauty sku:US-42061-01 options[qty]:1 options[US-21900-00][skus][US-11902-01]:1 options[US-21400-00][skus][US-11402-05]:1 options[US-22401-00][skus][US-12401-01]:1 options[US-21801-00][skus][US-11801-10]:1 */ $items = array(array("sku" => "US-42011-01", "qty" => $qty, "options" => array("US-22301-00" => array("skus" => array("US-12301-02" => 1, "US-12301-08" => 1)), "US-21801-00" => array("skus" => array("US-11801-08" => 1, "US-11801-10" => 1)), "US-22100-00" => array("skus" => array("US-12102-05" => 1, "US-12102-09" => 1))))); $coupons = array(); $productCredits = Money::fromFloat(0.0); //20.00//29.00//29.00//45.00//29.00//90.00//75.00//175.00//58.00 //$prices = $this->Order->getOrderCosts($address['postal_code'], $items,null, $coupons); $prices = $this->Order->getOrderCosts($address['postal_code'], $items, $productCredits, $coupons); //$prices = $this->getOrderCosts($address['country_id'], $items,null, $coupons); //echo "<pre>"; //print_r($prices);exit; $insert_order = TRUE; // $result = $this->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,null, $coupons,FALSE,$insert_order); $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address, Order::TYPE_PRODUCT, $productCredits, $coupons, FALSE, TRUE); // debug($result); // $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,$productCredits, $coupons,FALSE);//$insert_order $orderId = $this->Order->id; // $orderId = $this->Order->query("SELECT MAX(id) FROM orders"); // debug($this->Order->id); // debug($orderId); // debug($result); // exit; $orderPaymentResult = array("success" => false, "payments" => array(array('type' => 'creditcard', 'amount' => $prices['total']['total'], "transaction_id" => "Wohootest", "identifier" => "3123", 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'failed'))); $result = $this->Order->finalize($orderPaymentResult); // debug($prices['total']['total']); $orderPaymentResult = array("success" => true, "payments" => array(array('type' => 'creditcard', 'transaction_id' => 'Wohootest', 'amount' => $prices['total']['total'], 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'success', "identifier" => "3123"))); $result = $this->Order->finalize($orderPaymentResult); return $orderId; }
public function orderCreate($country_id, $presenterId, $userId, $hostmarket_id, $partyId) { Configure::write("market_id", (int) $country_id); if ($country_id == 1) { $postal_code = "20350-1000"; } else { if ($country_id == 2) { $postal_code = "K1A 0B1"; } else { if ($country_id == 3) { $postal_code = "0872"; } else { if ($country_id == 4) { $postal_code = "6000"; } else { if ($country_id == 5) { $postal_code = "NN8 4TH"; } else { if ($country_id == 7) { $postal_code = "01774"; } else { if ($country_id == 8) { $postal_code = "97439"; } else { if ($country_id == 6) { $country_id = 9; $postal_code = "54040"; } else { echo "I am from else block"; exit; } } } } } } } } // debug($postal_code); $address = array("first_name" => "testing", "last_name" => "last", "address1" => "Some address 1", "address2" => "Some address 2", "address3" => "Some address 3", "city" => "Awesome city", "state_id" => 20, "postal_code" => $postal_code, "email_address" => "*****@*****.**", "country_id" => $country_id); $promoterId = 2; $items = array(array("sku" => "US-12001-01", "qty" => 1)); $coupons = array(); $productCredits = Money::fromFloat(10.0); $prices = $this->Order->getOrderCosts($address['postal_code'], $items, $productCredits, $coupons); $insert_order = TRUE; $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address, Order::TYPE_PRODUCT, $productCredits, $coupons, FALSE, TRUE); $orderId = $this->Order->id; $orderPaymentResult = array("success" => false, "payments" => array(array('type' => 'creditcard', 'amount' => $prices['total']['total'], "transaction_id" => "Wohootest", "identifier" => "3123", 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'failed'))); $result = $this->Order->finalize($orderPaymentResult); $orderPaymentResult = array("success" => true, "payments" => array(array('type' => 'creditcard', 'transaction_id' => 'Wohootest', 'amount' => $prices['total']['total'], 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'success', "identifier" => "3123"))); $result = $this->Order->finalize($orderPaymentResult); return $orderId; }
private function _refundYCash($product_credit_id, $amount = NULL) { $this->loadModel('ProductCredit'); //get original record $productCredit = $this->ProductCredit->find("first", array("conditions" => array("id" => $product_credit_id))); if (empty($productCredit)) { return null; } $refund_amount = is_null($amount) ? Money::fromFloat($productCredit['ProductCredit']['amount']) : Money::fromFloat($amount); $methodId = $productCredit['ProductCredit']['product_credit_entry_type_id']; $typeId = $productCredit['ProductCredit']['product_credit_type_id']; $marketId = $productCredit['ProductCredit']['market_id']; $presenterId = $productCredit['ProductCredit']['presenter_id']; $userId = $productCredit['ProductCredit']['user_id']; $cost = $refund_amount; $entryUser = $productCredit['ProductCredit']['entry_user']; $referenceId = $productCredit['ProductCredit']['reference_id']; $result = $this->ProductCredit->credit($methodId, $typeId, $marketId, $presenterId, $userId, $cost, $entryUser, $referenceId); return $result; }
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; } }
public function orderCreate($country_id, $presenterId, $userId, $hostmarket_id, $partyId) { Configure::write("market_id", (int) $country_id); if ($country_id == 1) { $postal_code = "20350-1000"; } else { if ($country_id == 2) { $postal_code = "K1A 0B1"; } else { if ($country_id == 3) { $postal_code = "0872"; } else { if ($country_id == 4) { $postal_code = "6000"; } else { if ($country_id == 5) { $postal_code = "NN8 4TH"; } else { echo "I am from else block"; exit; } } } } } // debug($postal_code); $address = array("first_name" => "testing", "last_name" => "last", "address1" => "Some address 1", "address2" => "Some address 2", "address3" => "Some address 3", "city" => "Awesome city", "state_id" => 20, "postal_code" => $postal_code, "email_address" => "*****@*****.**", "country_id" => $country_id); $promoterId = 2; //$presenterId = 141683; // from presenter , we get market_id for orders /* sku:US-42011-01 options[qty]:1 options[US-22301-00][skus][US-12301-02]:1 options[US-22301-00][skus][US-12301-08]:1 options[US-21801-00][skus][US-11801-08]:1 options[US-21801-00][skus][US-11801-10]:1 options[US-22100-00][skus][US-12102-05]:1 options[US-22100-00][skus][US-12102-09]:1 sku:US-1017-00 options[qty]:1 */ $items = array(array("sku" => 'US-11201-05', "qty" => 5, "coupons" => array("1" => array("discount_percentage" => 50, "discount_flat" => Money::fromFloat(0), "name" => "Half Priced Item")))); $coupons = array(); $productCredits = Money::fromFloat(0.0); $prices = $this->Order->getOrderCosts($address['postal_code'], $items, $productCredits, $coupons); $insert_order = TRUE; $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address, Order::TYPE_PRODUCT, $productCredits, $coupons, FALSE, TRUE); $orderId = $this->Order->id; $orderPaymentResult = array("success" => false, "payments" => array(array('type' => 'creditcard', 'amount' => $prices['total']['total'], "transaction_id" => "Wohootest", "identifier" => "3123", 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'failed'))); $result = $this->Order->finalize($orderPaymentResult); // debug($prices['total']['total']); $orderPaymentResult = array("success" => true, "payments" => array(array('type' => 'creditcard', 'transaction_id' => 'Wohootest', 'amount' => $prices['total']['total'], 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'success', "identifier" => "3123"))); $result = $this->Order->finalize($orderPaymentResult); return $orderId; }
public function testCollectionFourYcash() { $data1 = array('sku' => 'US-42011-01', 'options' => array('qty' => 4, "US-22301-00" => array("skus" => array("US-12301-03" => 1, "US-12301-0" => 1)), "US-21801-00" => array("skus" => array("US-11801-04" => 1, "US-11801-10" => 1)), "US-22100-00" => array("skus" => array("US-12102-04" => 2)))); $data2 = array("market_id" => 1, "productcredits" => 350.0); $clear1 = $this->testAction('/shoppingcart/clear', array('return' => 'vars')); $adding = $this->testAction('shoppingcart/add', array('data' => $data1, 'method' => 'post', 'return' => 'vars')); $CartItems = $this->testAction('/shoppingcart/view', array('method' => 'post', 'data' => $data2, 'return' => 'vars')); // debug($CartItems); $result = array('code' => (int) 200, 'error' => false, 'result' => array((int) 0 => array('item_id' => '513', 'image' => array('name' => 'Pucker Up', 'thumb_path' => '/en_US/img/product_images/US-42011-01-thumb.jpg', 'file_path' => '/en_US/img/product_images/US-42011-01.jpg'), 'sku' => 'US-42011-01', 'name' => 'Pucker Up', 'dailyspecial' => false, 'backordered' => false, 'childBackordered' => false, 'item_availability' => array('id' => '883', 'item_id' => '539', 'item_availability_id' => '3', 'start_date' => '2015-04-24 17:50:59', 'end_date' => null, 'estimated_date' => null, 'Item' => array('id' => '539', 'item_type_id' => '1', 'item_sequence' => '91515', 'sku' => 'US-91515-05', 'name' => 'Three Little Words necklace', 'orderable' => false, 'shippable' => '1', 'taxable' => '1', 'in_stock' => true, 'enabled' => '1', 'redirect_sku' => null, 'max_qty' => null, 'item_availability_id' => '3', 'handling_fee' => null, 'manufacturer_item_code' => null, 'qty_required' => null, 'prop65_flag' => null, 'shipment_class' => 'D', 'tax_type_id' => null, 'variantSkus' => '')), 'backorder_message' => 'Due to overwhelming popularity, individual orders of Three Little Words necklace are on temporary back order. Orders for this item can still be placed. Any other items ordered will ship immediately, with back ordered items shipping separately on a first come, first serve basis.', 'backorder_title' => 'This item is temporarily on back order', 'type_id' => '4', 'quantity' => (int) 4, 'price' => Money::fromFloat(99.0), 'points' => (int) 3960, 'commission' => Money::fromFloat(99.0), 'subtotal' => Money::fromFloat(396.0), 'commissionSubtotal' => Money::fromFloat(396.0), 'originalsubtotal' => Money::fromFloat(396.0), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(5.5), 'discount' => Money::fromFloat(0.0), 'discounts' => array(), 'kudosItem' => false, 'hpDisabled' => false, 'total' => Money::fromFloat(396.0), 'included' => array((int) 0 => array('name' => 'Saucy', 'shortname' => 'Saucy', 'id' => '481', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-12301-03', 'image' => array('name' => 'Saucy', 'thumb_path' => '/en_US/img/product_images/US-12301-03-thumb.jpg', 'file_path' => '/en_US/img/product_images/US-12301-03.jpg'), 'item_availability' => array('id' => '796', 'item_id' => '481', 'item_availability_id' => '3', 'start_date' => '2015-03-01 00:19:54', 'end_date' => null, 'estimated_date' => null)), (int) 1 => array('name' => 'Lucrative Lip Gloss - Livid', 'shortname' => 'Livid', 'id' => '323', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-11801-04', 'image' => array('name' => 'Livid', 'thumb_path' => '/en_US//img/product_images/US-11801-04-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-11801-04.jpg'), 'item_availability' => array('id' => '438', 'item_id' => '323', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null)), (int) 2 => array('name' => 'Lucrative Lip Gloss - Luxe', 'shortname' => 'Luxe', 'id' => '329', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-11801-10', 'image' => array('name' => 'Luxe', 'thumb_path' => '/en_US//img/product_images/US-11801-10-thumb.jpg', 'file_path' => '/en_US//img/product_images/US-11801-10.jpg'), 'item_availability' => array('id' => '641', 'item_id' => '329', 'item_availability_id' => '3', 'start_date' => '2014-12-05 14:50:28', 'end_date' => null, 'estimated_date' => null)), (int) 3 => array('name' => 'Pencil Sharpener', 'shortname' => 'Precision Pencil Sharpener', 'id' => '356', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '0', 'sku' => 'US-53001-01', 'item_availability' => array('id' => '471', 'item_id' => '356', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Precision Pencil Sharpener', 'thumb_path' => '/en_US/img/product_images/US-53001-01-thumb.jpg', 'file_path' => '/en_US/img/product_images/US-53001-01.jpg'), 'tag' => '')), 'options' => array('US-22301-00' => array('skus' => array('US-12301-03' => (int) 1, 'US-12301-0' => (int) 1)), 'US-21801-00' => array('skus' => array('US-11801-04' => (int) 1, 'US-11801-10' => (int) 1)), 'US-22100-00' => array('skus' => array('US-12102-04' => (int) 2))), 'prop65_flag' => null), 'total' => array('subtotal' => Money::fromFloat(396.0), 'discounts' => array(), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(0.0), 'total' => Money::fromFloat(396.0), 'kudos_total' => Money::fromFloat(396.0), 'productcredits' => Money::fromFloat(0.0), 'commissionable' => Money::fromFloat(396.0), 'commissionable_total' => Money::fromFloat(396.0), 'charge' => Money::fromFloat(396.0), 'usedCoupons' => array(), 'points' => (double) 3960, 'market_commissionable_total' => Money::fromFloat(396.0), 'market_commissionable' => Money::fromFloat(396.0), 'presenter_commissionable' => Money::fromFloat(396.0), 'appliedPoints' => (double) 3960, 'negativePoints' => (double) 0, 'totalItemCount' => (double) 7, 'toFreeShipping' => Money::fromFloat(-396.0), 'prop65_flag' => false, 'freeCatalog' => false, 'toFreeCatalog' => '50.00', 'errors_type' => 'none', 'errors' => 'none'))); array('code' => (int) 200, 'error' => false, 'result' => array((int) 0 => array('item_id' => '513', 'image' => array('name' => null, 'thumb_path' => null, 'file_path' => null), 'sku' => 'US-42011-01', 'name' => null, 'dailyspecial' => false, 'backordered' => false, 'childBackordered' => false, 'item_availability' => array('id' => '700', 'item_id' => '548', 'item_availability_id' => '3', 'start_date' => '2015-04-26 22:46:42', 'end_date' => null), 'backorder_message' => 'Due to overwhelming popularity, individual orders of Three Little Words necklace are on temporary back order. Orders for this item can still be placed. Any other items ordered will ship immediately, with back ordered items shipping separately on a first come, first serve basis.', 'backorder_title' => 'This item is temporarily on back order', 'type_id' => '4', 'quantity' => (int) 4, 'price' => Money::fromFloat(99.0), 'points' => (int) 3960, 'commission' => Money::fromFloat(99.0), 'subtotal' => Money::fromFloat(396.0), 'commissionSubtotal' => Money::fromFloat(396.0), 'originalsubtotal' => Money::fromFloat(396.0), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(5.5), 'discount' => Money::fromFloat(0.0), 'discounts' => array(), 'kudosItem' => false, 'hpDisabled' => false, 'total' => Money::fromFloat(396.0), 'included' => array(), 'options' => array('US-22301-00' => array('skus' => array('US-12301-03' => (int) 1, 'US-12301-0' => (int) 1)), 'US-21801-00' => array('skus' => array('US-11801-04' => (int) 1, 'US-11801-10' => (int) 1)), 'US-22100-00' => array('skus' => array('US-12102-04' => (int) 2))), 'prop65_flag' => null), 'total' => array('subtotal' => Money::fromFloat(396.0), 'discounts' => array(), 'shipping' => Money::fromFloat(0.0), 'total' => Money::fromFloat(396.0), 'kudos_total' => Money::fromFloat(396.0), 'productcredits' => Money::fromFloat(0.0), 'commissionable' => Money::fromFloat(396.0), 'commissionable_total' => Money::fromFloat(396.0), 'charge' => Money::fromFloat(396.0), 'usedCoupons' => array(), 'points' => (double) 3960, 'market_commissionable_total' => Money::fromFloat(396.0), 'market_commissionable' => Money::fromFloat(396.0), 'presenter_commissionable' => Money::fromFloat(396.0), 'appliedPoints' => (double) 3960, 'negativePoints' => (double) 0, 'totalItemCount' => (double) 7, 'toFreeShipping' => Money::fromFloat(-396.0), 'prop65_flag' => false, 'freeCatalog' => false, 'toFreeCatalog' => '50.00', 'errors_type' => 'none', 'errors' => 'none', 'taxes' => Money::fromFloat(0.0)))); $this->assertEquals($result, $CartItems); // debug($adding); // exit; /* sponsor_id:248679 market_id:1 first_name:test last_name:test2 email:venubabu@1800agile.com address1:1000 Navy Pentagon address2: address3: city:Washington county: state:district of columbia postal_code:20350-1000 qas_state:District of Columbia qas_country:1 sameAsShipping:on billing_market_id:1 billingEmail: billingAddress1: billingAddress2: billingCity: billingState:washington billingZip: billingCardholderFirstName:test billingCardholderLastName:test1 cardNum:754763453253634 cardCode:235 cardExpMonth:04 cardExpYear:2017 items[0][sku]:US-42011-01 items[0][qty]:1 items[0][options][US-22301-00][skus][US-12301-03]:1 items[0][options][US-22301-00][skus][US-12301-06]:1 items[0][options][US-21801-00][skus][US-11801-06]:1 items[0][options][US-21801-00][skus][US-11801-09]:1 items[0][options][US-22100-00][skus][US-12101-05]:1 items[0][options][US-22100-00][skus][US-12102-04]:1 items[1][sku]:US-91515-05 items[1][kudosItem]:true items[1][qty]:1 party_id:Select the party productcredits:0 commissionable_total:99.00 */ }
public function testOrderShippingCoupon() { $address = array("first_name" => "testing", "last_name" => "last", "address1" => "Some address 1", "address2" => "Some address 2", "address3" => "Some address 3", "city" => "Awesome city", "state_id" => 20, "postal_code" => "84003", "email_address" => "*****@*****.**"); $promoterId = 1; $presenterId = 1; $userId = 2; $items = array(array("sku" => "US-1010-00", "qty" => 1, "options" => array("US-1012-00" => array("US-1011-00" => array("skus" => array("US-1011-02" => 1, "US-1011-03" => 1, "US-1011-04" => 1, "US-1011-05" => 1)))))); $coupons = array(4 => array("discount_percentage" => 50, "discount_flat" => Money::fromFloat(0), "name" => "Online Share", "order_scope_id" => Coupon::SCOPE_SHIPPING)); $prices = $this->Order->getOrderCosts($address['postal_code'], $items, null, $coupons); $this->assertArraysEqual($prices['total'], array('subtotal' => Money::fromFloat(99.98999999999999), 'discounts' => array(4 => array('name' => 'Online Share', 'amount' => Money::fromFloat(2.75), 'scope' => Coupon::SCOPE_SHIPPING)), 'taxes' => Money::fromFloat(6.75), 'shipping' => Money::fromFloat(5.5), 'total' => Money::fromFloat(109.49), 'productcredits' => Money::fromFloat(0), 'commissionable_total' => Money::fromFloat(99.98999999999999), 'charge' => Money::fromFloat(109.49), "usedCoupons" => array(), "totalItemCount" => 1, "toFreeShipping" => Money::fromFloat(0.01))); $result = $this->Order->createOrder($promoterId, $presenterId, $userId, 0, $items, $address, Order::TYPE_PRODUCT, null, $coupons); $orderId = $this->Order->id; $this->assertArraysEqual($result['total'], array('subtotal' => Money::fromFloat(99.98999999999999), 'discounts' => array(4 => array('name' => 'Online Share', 'amount' => Money::fromFloat(2.75), 'scope' => Coupon::SCOPE_SHIPPING)), 'taxes' => Money::fromFloat(6.75), 'shipping' => Money::fromFloat(5.5), 'total' => Money::fromFloat(109.49), 'productcredits' => Money::fromFloat(0), 'commissionable_total' => Money::fromFloat(99.98999999999999), 'charge' => Money::fromFloat(109.49), "usedCoupons" => array(4 => array('reference_id' => '6', 'amount' => Money::fromFloat(2.75))), "totalItemCount" => 1, "toFreeShipping" => Money::fromFloat(0.01))); }
/** * Add new product line items with the item data passed * * @param $address * @param $market * @param $lineItems * @param null $type * @param bool|true $is_presenter * @param null $user * @param null $order_id * @param null $last_date * @return Money|stdClass */ public function get_tax($address, $market, $lineItems, $type = null, $is_presenter = true, $user = null, $order_id = null, $last_date = null) { try { if ($address['postal_code'] === null) { //Make no api call if no destination zip is specified. or if not a test server unit feb 1st; return Money::fromFloat(0); } else { $documentNumber = $order_id; $api_call = array('cancel' => 'urn:InvoiceRequest', 'invoice' => 'urn:InvoiceRequest', 'quote' => 'urn:QuotationRequest', 'distribute' => 'urn:DistributeTaxRequest'); $order_id_postfix = array('cancel' => '-r1', 'invoice' => '', 'quote' => '', 'distribute' => '-r2'); $invoiceXMLArr = array('@documentNumber' => !is_null($order_id) ? $order_id . $order_id_postfix[$type] : "", '@documentDate' => !is_null($last_date) ? $last_date : date('Y-m-d'), '@postingDate' => !is_null($last_date) ? $last_date : date('Y-m-d'), '@retunAssitedParametersIndicator' => 'true', '@transactionType' => "SALE", 'urn:Currency' => array('@isoCurrencyCodeAlpha' => $market['Market']['currency']), 'urn:Seller' => array('urn:Company' => 'YOUGLB', 'urn:Division' => 'YOUUSA'), 'urn:Customer' => array('urn:CustomerCode' => !is_null($user) && isset($user['User']['id']) ? $user['User']['id'] : 'BuyerCode', 'urn:Destination' => array('urn:PostalCode' => strtoupper($address['postal_code']), 'urn:Country' => $market['Market']['name'])), 'urn:LineItem' => array()); // if(!is_null($user) && isset($user['Presenters']['tax_exempt']) && $user['Presenters']['tax_exempt']) { // $invoiceXMLArr['urn:Customer']['@isTaxExempt'] = 'true'; // } $itemCount = 1; //TODO will need to adjust for outside markets if (strlen($address['postal_code']) > 5 && $market['Market']['id'] == 1) { //if the zip is greater than five QAS has found a corresponding adresses if not we can assume that only the zip is valid. $invoiceXMLArr['urn:Customer']['urn:Destination']['urn:City'] = $address['city']; $invoiceXMLArr['urn:Customer']['urn:Destination']['urn:MainDivision'] = $address['state']; } if ($type == 'distribute') { foreach ($lineItems as $item) { if ($item['tax_amount'] != '-0.00') { $invoiceXMLArr['urn:LineItem'][] = $this->addDistributeTaxLine($item, $itemCount, $type, $user, $market['Market']['id'], $order_id); $itemCount++; } } } else { foreach ($lineItems as $item) { if ($type == "cancel" && ($is_presenter && $item['originalSubtotal'] != "-0.00" || $item['subtotal'] != '-0.00')) { $invoiceXMLArr['urn:LineItem'][] = $this->addLineItem($item, $itemCount, $type, $is_presenter, $user, $market['Market']['id'], $order_id); $itemCount++; } else { if ($is_presenter && $item['originalSubtotal'] != 0 || $item['subtotal'] != '0.00') { $invoiceXMLArr['urn:LineItem'][] = $this->addLineItem($item, $itemCount, $type, $is_presenter, $user, $market['Market']['id'], $order_id); $itemCount++; } } } } //send shipping $item = array('qty' => 1, 'originalSubtotal' => $market['shipping']['total']->display, 'subtotal' => $market['shipping']['total']->display, 'tax_type' => 'SHIPPING', 'sku' => 'shipping', 'display_name' => 'shipping'); $invoiceXMLArr['urn:LineItem'][] = $this->addLineItem($item, $itemCount, $type, $is_presenter, $user, $market['Market']['id'], $order_id); $request_type = $api_call[$type]; $vertexWrapper = $this->getVertexWrapper(); $vertexWrapper['soapenv:Envelope']['soapenv:Body']['urn:VertexEnvelope'][$request_type] = $invoiceXMLArr; $requestXML = Xml::build($vertexWrapper); $response = $this->sendRequest($requestXML); $result = $this->processResponse($response, $requestXML->asXML(), $type); if (!$result->success) { $result->source = "UNITED STATES"; $result->destination = $market; $result->sent = $requestXML->asXML(); } return $result; } } catch (Exception $e) { $result = new stdClass(); $result->error_type = 'General'; $result->success = false; $result->error_msg = $e->getMessage(); $result->source = ""; $result->destination = ""; $result->sent = ""; $result->received = $e->getMessage(); return $result; } }
public function testMexicoItem() { Configure::write("market_id", 6); $data1 = array("sku" => "US-91515-06", "options" => array("qty" => 1)); $clear1 = $this->testAction('/shoppingcart/clear', array('return' => 'vars')); $adding = $this->testAction('shoppingcart/add', array('data' => $data1, 'method' => 'post', 'return' => 'vars')); $CartItems = $this->testAction('/shoppingcart/view', array('method' => 'post', 'data' => $data2, 'return' => 'vars')); // debug($CartItems); // exit; $expected1 = array('code' => (int) 200, 'error' => false, 'result' => array((int) 0 => array('item_id' => '571', 'image' => array('name' => 'Go for Glitz bundle', 'thumb_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/styles/thumbnail/public/US-91515-06.jpg?nNxYV3BDSK0Oe1dzgLu0cKeOw7lSUYY5&itok=rsMi9wMU', 'file_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/US-91515-06.jpg'), 'sku' => 'US-91515-06', 'name' => 'Go for Glitz bundle', 'dailyspecial' => false, 'backordered' => false, 'childBackordered' => false, 'item_availability' => array('id' => null, 'item_id' => null, 'item_availability_id' => null, 'start_date' => null, 'end_date' => null, 'estimated_date' => null), 'backorder_message' => 'Due to overwhelming popularity, individual orders of Go For Glitz Free Bag are on temporary back order. Orders for this item can still be placed. Any other items ordered will ship immediately, with back ordered items shipping separately on a first come, first serve basis.', 'backorder_title' => 'This item is temporarily on back order', 'type_id' => '3', 'quantity' => (int) 1, 'price' => Money::fromFloat('1305.00'), 'points' => (int) 75, 'commission' => Money::fromFloat(75.0), 'subtotal' => Money::fromFloat('1305.00'), 'commissionSubtotal' => Money::fromFloat(75.0), 'originalsubtotal' => Money::fromFloat('1305.00'), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(150.0), 'discount' => Money::fromFloat(0.0), 'discounts' => array(), 'kudosItem' => false, 'hpDisabled' => true, 'total' => Money::fromFloat('1305.00'), 'included' => array((int) 0 => array('name' => 'Moodstruck 3D Fiber Lashes', 'shortname' => 'Moodstruck 3D Fiber Lashes', 'id' => '24', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-1017-00', 'item_availability' => array('id' => '24', 'item_id' => '24', 'item_availability_id' => '3', 'start_date' => '2012-10-31 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Magnify and enhance your OWN lashes!', 'thumb_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/styles/thumbnail/public/US-1017-00_3.jpg?kOgFWlYDaqlb6o3p9UG.xkcHwzTL5LeN&itok=K795oOYi', 'file_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/US-1017-00_3.jpg'), 'tag' => ''), (int) 1 => array('name' => 'Tenacious', 'shortname' => 'Tenacious', 'id' => '560', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-12501-03', 'item_availability' => array('id' => '905', 'item_id' => '560', 'item_availability_id' => '1', 'start_date' => '2015-05-21 10:54:12', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Tenacious', 'thumb_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/styles/thumbnail/public/US-12501-03.jpg?itok=0SnVLsFr', 'file_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/US-12501-03.jpg'), 'tag' => ''), (int) 2 => array('name' => 'Loyal', 'shortname' => 'Loyal', 'id' => '326', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-11801-07', 'item_availability' => array('id' => '441', 'item_id' => '326', 'item_availability_id' => '3', 'start_date' => '2014-09-01 00:00:00', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Loyal', 'thumb_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/styles/thumbnail/public/US-11801-07_0.jpg?HtCEu2URnvqP0bKp1RtXAf5lQ0M_aT9r&itok=g_u_nwdH', 'file_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/US-11801-07_0.jpg'), 'tag' => ''), (int) 3 => array('name' => 'Cream Shadow Brush', 'shortname' => 'Cream Shadow Brush', 'id' => '494', 'orderable' => true, 'in_stock' => true, 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => '1', 'sku' => 'US-51041-01', 'item_availability' => array('id' => '809', 'item_id' => '494', 'item_availability_id' => '3', 'start_date' => '2015-03-01 00:20:02', 'end_date' => null, 'estimated_date' => null), 'image' => array('name' => 'Cream Shadow Brush', 'thumb_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/styles/thumbnail/public/US-51041-01_0.jpg?Xr.rvOeUQSLrcij8LamDRi.V_0n7yk9T&itok=Gkl8-jOP', 'file_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/US-51041-01_0.jpg'), 'tag' => '')), 'options' => array(), 'prop65_flag' => null), (int) 1 => array('item_id' => '570', 'image' => array('name' => 'peof="foaf:Image" src="https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/US-91515-06-alt1_0.jpg" width="601" height="456" alt="', 'thumb_path' => 'http://drupal.youniqueproducts.com/s3/files/styles/thumbnail/public/US-91515-06-alt1_0.jpg?itok=ikL-D6O4', 'file_path' => 'https://younique-dfiles.s3-us-west-2.amazonaws.com/s3fs-public/US-91515-06-alt1_0.jpg'), 'sku' => 'US-60009-00', 'name' => 'FREE exclusive Younique Makeup Travel Bag', 'dailyspecial' => false, 'backordered' => false, 'childBackordered' => false, 'item_availability' => array('id' => null, 'item_id' => null, 'item_availability_id' => null, 'start_date' => null, 'end_date' => null, 'estimated_date' => null), 'backorder_message' => 'Due to overwhelming popularity, individual orders of Go For Glitz Free Bag are on temporary back order. Orders for this item can still be placed. Any other items ordered will ship immediately, with back ordered items shipping separately on a first come, first serve basis.', 'backorder_title' => 'This item is temporarily on back order', 'type_id' => '1', 'quantity' => (int) 1, 'price' => Money::fromFloat('0.00'), 'points' => (int) 0, 'commission' => Money::fromFloat('0.00'), 'subtotal' => Money::fromFloat('0.00'), 'commissionSubtotal' => Money::fromFloat('0.00'), 'originalsubtotal' => Money::fromFloat('0.00'), 'taxes' => Money::fromFloat('0.00'), 'shipping' => Money::fromFloat('150.00'), 'discount' => Money::fromFloat('0.00'), 'discounts' => array(), 'kudosItem' => true, 'hpDisabled' => false, 'total' => Money::fromFloat('0.00'), 'included' => array(), 'options' => array(), 'prop65_flag' => null), 'total' => array('subtotal' => Money::fromFloat('1305.00'), 'discounts' => array(), 'taxes' => Money::fromFloat(0.0), 'taxes_by_type' => array(), 'shipping' => Money::fromFloat(150.0), 'total' => Money::fromFloat('1455.00'), 'kudos_total' => Money::fromFloat('1305.00'), 'donation' => Money::fromFloat(0.0), 'total_w_donation' => Money::fromFloat('1455.00'), 'charge_w_donation' => Money::fromFloat('1455.00'), 'predonation' => Money::fromFloat('1455.00'), 'productcredits' => Money::fromFloat(0.0), 'commissionable' => Money::fromFloat(75.0), 'commissionable_total' => Money::fromFloat(75.0), 'charge' => Money::fromFloat('1455.00'), 'usedCoupons' => array(), 'points' => (int) 75, 'market_commissionable_total' => Money::fromFloat('1305.00'), 'market_commissionable' => Money::fromFloat('1305.00'), 'presenter_commissionable' => Money::fromFloat(75.0), 'appliedPoints' => (double) 75, 'negativePoints' => (double) 0, 'totalItemCount' => (int) 2, 'toFreeShipping' => Money::fromFloat('998694.99'), 'prop65_flag' => false, 'freeCatalog' => false, 'toFreeCatalog' => 0.0, 'errors_type' => 'none', 'errors' => 'none'))); $this->assertEqual($CartItems, $expected1); }
public function orderCreate($country_id, $presenterId, $userId, $hostmarket_id, $partyId) { Configure::write("market_id", (int) $country_id); if ($country_id == 1) { $postal_code = "20350-1000"; } else { if ($country_id == 2) { $postal_code = "K1A 0B1"; } else { if ($country_id == 3) { $postal_code = "0872"; } else { if ($country_id == 4) { $postal_code = "6000"; } else { if ($country_id == 5) { $postal_code = "NN8 4TH"; } else { if ($country_id == 6) { $postal_code = "50450"; } else { echo "I am from else block"; exit; } } } } } } // debug($postal_code); $address = array("first_name" => "testing", "last_name" => "last", "address1" => "Some address 1", "address2" => "Some address 2", "address3" => "Some address 3", "city" => "Awesome city", "state_id" => 20, "postal_code" => $postal_code, "email_address" => "*****@*****.**", "country_id" => $country_id); $promoterId = 2; //$presenterId = 141683; // from presenter , we get market_id for orders /* sku:US-42011-01 options[qty]:1 options[US-22301-00][skus][US-12301-02]:1 options[US-22301-00][skus][US-12301-08]:1 options[US-21801-00][skus][US-11801-08]:1 options[US-21801-00][skus][US-11801-10]:1 options[US-22100-00][skus][US-12102-05]:1 options[US-22100-00][skus][US-12102-09]:1 sku:US-1017-00 options[qty]:1 */ $items = array(array("sku" => "US-1017-00", "qty" => 1)); $coupons = array(); $productCredits = Money::fromFloat(0.0); //20.00//29.00//29.00//45.00//29.00//90.00//75.00//175.00//58.00 //$prices = $this->Order->getOrderCosts($address['postal_code'], $items,null, $coupons); $prices = $this->Order->getOrderCosts($address['postal_code'], $items, $productCredits, $coupons); //$prices = $this->getOrderCosts($address['country_id'], $items,null, $coupons); //echo "<pre>"; //print_r($prices);exit; $insert_order = TRUE; // $result = $this->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,null, $coupons,FALSE,$insert_order); $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address, Order::TYPE_PRODUCT, $productCredits, $coupons, FALSE, TRUE); $orderId = $this->Order->id; $expected = array((int) 0 => array('item_id' => '24', 'image' => array('name' => 'Moodstruck 3D fiber Lashes', 'thumb_path' => '/resources/en_US/img/product_images/US-1017-00-thumb.jpg', 'file_path' => '/resources/en_US/img/product_images/US-1017-00.jpg'), 'sku' => 'US-1017-00', 'name' => 'Moodstruck 3D Fiber Lashes', 'dailyspecial' => false, 'backordered' => false, 'childBackordered' => false, 'item_availability' => array('id' => '24', 'item_id' => '24', 'item_availability_id' => '3', 'start_date' => '2012-10-31 00:00:00', 'end_date' => null, 'estimated_date' => null), 'backorder_message' => 'Due to overwhelming popularity, individual orders of Moodstruck 3D fiber Lashes are on temporary back order. Orders for this item can still be placed. Any other items ordered will ship immediately, with back ordered items shipping separately on a first come, first serve basis.', 'backorder_title' => 'This item is temporarily on back order', 'type_id' => '1', 'quantity' => (int) 1, 'price' => Money::fromFloat(505.0), 'points' => (int) 290, 'commission' => Money::fromFloat(29.0), 'subtotal' => Money::fromFloat(505.0), 'commissionSubtotal' => Money::fromFloat(29.0), 'originalsubtotal' => Money::fromFloat(505.0), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(150.0), 'discount' => Money::fromFloat(0.0), 'discounts' => array(), 'kudosItem' => false, 'hpDisabled' => false, 'total' => Money::fromFloat(505.0), 'included' => array(), 'options' => array(), 'prop65_flag' => '0'), 'total' => array('subtotal' => Money::fromFloat(505.0), 'discounts' => array(), 'taxes' => Money::fromFloat(0.0), 'shipping' => Money::fromFloat(150.0), 'total' => Money::fromFloat(655.0), 'kudos_total' => Money::fromFloat(505.0), 'productcredits' => Money::fromFloat(0.0), 'commissionable' => Money::fromFloat(29.0), 'commissionable_total' => Money::fromFloat(29.0), 'charge' => Money::fromFloat(655.0), 'usedCoupons' => array(), 'points' => (int) 290, 'market_commissionable_total' => Money::fromFloat(505.0), 'market_commissionable' => Money::fromFloat(505.0), 'presenter_commissionable' => Money::fromFloat(29.0), 'appliedPoints' => (double) 290, 'negativePoints' => (double) 0, 'totalItemCount' => (int) 1, 'toFreeShipping' => Money::fromFloat(9494.99), 'prop65_flag' => false, 'freeCatalog' => null, 'toFreeCatalog' => '0.00', 'errors_type' => 'none', 'errors' => 'none', 'order_id' => $orderId)); //debug($result);exit; // debug($result); // $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,$productCredits, $coupons,FALSE);//$insert_order // $orderId = $this->Order->query("SELECT MAX(id) FROM orders"); // debug($this->Order->id); // debug($orderId); // debug($result); // exit; $orderPaymentResult = array("success" => false, "payments" => array(array('type' => 'creditcard', 'amount' => $prices['total']['total'], "transaction_id" => "Wohootest", "identifier" => "3123", 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'failed'))); $result = $this->Order->finalize($orderPaymentResult); // debug($prices['total']['total']); $orderPaymentResult = array("success" => true, "payments" => array(array('type' => 'creditcard', 'transaction_id' => 'Wohootest', 'amount' => $prices['total']['total'], 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'success', "identifier" => "3123"))); $result = $this->Order->finalize($orderPaymentResult); //debug($result);exit; return $orderId; }
public function orderCreate($country_id, $presenterId, $userId, $hostmarket_id, $partyId) { Configure::write("market_id", (int) $country_id); if ($country_id == 1) { $postal_code = "20350-1000"; } else { if ($country_id == 2) { $postal_code = "K1A 0B1"; } else { if ($country_id == 3) { $postal_code = "0872"; } else { if ($country_id == 4) { $postal_code = "6000"; } else { if ($country_id == 5) { $postal_code = "NN8 4TH"; } else { echo "I am from else block"; exit; } } } } } // debug($postal_code); $address = array("first_name" => "testing", "last_name" => "last", "address1" => "Some address 1", "address2" => "Some address 2", "address3" => "Some address 3", "city" => "Awesome city", "state_id" => 20, "postal_code" => $postal_code, "email_address" => "*****@*****.**", "country_id" => $country_id); $promoterId = 2; //$presenterId = 141683; // from presenter , we get market_id for orders $items = array(array("sku" => "US-42031-01", "qty" => 5, "options" => array("US-21000-00" => array("skus" => array("US-11001-01" => 1, "US-11001-08" => 1)), "US-22100-00" => array("skus" => array("US-12101-03" => 1, "US-12101-04" => 1)), "US-21400-00" => array("skus" => array("US-11401-07" => 1)), "US-22401-00" => array("skus" => array("US-12401-03" => 1)), "US-22301-00" => array("skus" => array("US-12301-07" => 1)))), array("sku" => "US-1017-00", "qty" => 1, "coupons" => array("1" => array("discount_percentage" => 50, "discount_flat" => Money::fromFloat(0), "name" => "Half Priced Item"))), array("sku" => "US-53021-01", "qty" => 1, "coupons" => array("1" => array("discount_percentage" => 50, "discount_flat" => Money::fromFloat(0), "name" => "Half Priced Item"))), array("sku" => "US-42021-01", "qty" => 3, "options" => array("US-22301-00" => array("skus" => array("US-12301-02" => 1)), "US-22501-00" => array("skus" => array("US-12501-01" => 1)), "US-22401-00" => array("skus" => array("US-12401-02" => 1))))); $coupons = array(); $productCredits = Money::fromFloat(800.0); //20.00//29.00//29.00//45.00//29.00//90.00//75.00//175.00//58.00 //$prices = $this->Order->getOrderCosts($address['postal_code'], $items,null, $coupons); $prices = $this->Order->getOrderCosts($address['postal_code'], $items, $productCredits, $coupons); //$prices = $this->getOrderCosts($address['country_id'], $items,null, $coupons); //echo "<pre>"; //print_r($prices);exit; $insert_order = TRUE; // $result = $this->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,null, $coupons,FALSE,$insert_order); $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address, Order::TYPE_PRODUCT, $productCredits, $coupons, FALSE, TRUE); // debug($result); // $result = $this->Order->createOrder($promoterId, $presenterId, $userId, $partyId, $items, $address,Order::TYPE_PRODUCT,$productCredits, $coupons,FALSE);//$insert_order $orderId = $this->Order->id; // $orderId = $this->Order->query("SELECT MAX(id) FROM orders"); // debug($this->Order->id); // debug($orderId); // debug($result); // exit; $orderPaymentResult = array("success" => false, "payments" => array(array('type' => 'creditcard', 'amount' => $prices['total']['total'], "transaction_id" => "Wohootest", "identifier" => "3123", 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'failed'))); $result = $this->Order->finalize($orderPaymentResult); // debug($prices['total']['total']); $orderPaymentResult = array("success" => true, "payments" => array(array('type' => 'creditcard', 'transaction_id' => 'Wohootest', 'amount' => $prices['total']['total'], 'cardholder' => 'Test wohoo', 'billingzip' => '84003', 'cardnum' => '123123123', 'carexp' => '12/2015', 'cardcode' => '962', 'status' => 'success', "identifier" => "3123"))); $result = $this->Order->finalize($orderPaymentResult); return $orderId; }
public function testCreateOrderLineItemsAccident() { $this->expectException("Exception", "Somehow we were about to order the wrong qty"); $result = $this->Item->createOrderLineItems(1, 2, Money::fromString(99), Money::fromString(99), 1, Money::fromFloat(99), Money::fromString(99), Money::fromFloat(0), Money::fromString(3.2), 0, date("Y-m-d H:i:s"), array("US-1012-00" => array("US-1011-00" => array("skus" => array("US-1011-00" => 1))))); }