public function getCoupons()
 {
     $couponDao = new CouponDao();
     $customerId = Mage::getSingleton('customer/session')->getId();
     $coupons = $couponDao->getOverviewByCustomerId($customerId);
     return $coupons;
 }
Example #2
0
 public function getStampCard()
 {
     $couponDao = new CouponDao();
     $customerId = Mage::getSingleton('customer/session')->getId();
     $coupons = $couponDao->getOverviewByCustomerId($customerId);
     foreach ($coupons as $coupon) {
         $aantal = $coupon['aantalproducten'];
         $duurste = $coupon['duursteproduct'];
         $value = array_values($coupon);
     }
     return $coupons;
 }
Example #3
0
 public function getStampCard()
 {
     $stampcard = $this->getCustomer()->getPrimaryShippingAddress();
     $couponDao = new CouponDao();
     $customerId = Mage::getSingleton('customer/session')->getId();
     $coupons = $couponDao->getOverviewByCustomerId($customerId);
     foreach ($coupons as $coupon) {
         $aantal = $coupon['aantalproducten'];
         $duurste = $coupon['duursteproduct'];
         $value = array_values($coupon);
         echo " copuon  {$aantal} en {$duurste}";
         Mage::log("data {$value}", null, 'custom.log');
     }
     return $coupons;
     //        if( $stampcard instanceof Varien_Object ) {
     //            return $stampcard->format('html');
     //        } else {
     //            return Mage::helper('customer')->__('You have not set a default shipping address.');
     //        }
 }
Example #4
0
 public function canApply($item, $orderId)
 {
     Mage::log("canApply items ", null, 'custom.log');
     $this->productId = $item->getProductId();
     $_product = Mage::getModel('catalog/product')->load($item->getProductId());
     $this->manufacturerName = $_product->getAttributeText('manufacturer');
     $couponDao = new CouponDao();
     $customerId = Mage::getSingleton('customer/session')->getId();
     $coupon = $couponDao->loadCouponByBrand($this->manufacturerName);
     if ($customerId != null && $coupon != null) {
         Mage::log("can apply: load completed  ", null, 'custom.log');
         $couponSaving = $couponDao->loadCompletedCouponSaving($coupon->getCouponId(), $customerId);
         Mage::log($couponSaving, null, 'custom.log');
         if ($couponSaving == null) {
             Mage::log($couponSaving, null, 'custom.log');
             Mage::log("can apply: completed was null  ", null, 'custom.log');
             $couponSaving = $couponDao->loadInCartCouponSaving($coupon->getCouponId(), $customerId);
         }
         if ($couponSaving != null) {
             list($requiredNumberOfProducts, $numberOfProductsOrdered, $maxPaid) = $couponDao->getNumberOfProductsOrderdForSavingCoupon($couponSaving, $customerId);
             Mage::log("stap 1   ", null, 'custom.log');
             if ($requiredNumberOfProducts != 0) {
                 Mage::log("stap 2  ", null, 'custom.log');
                 $this->coupon = true;
                 Mage::log($maxPaid >= $_product->getPrice(), null, 'custom.log');
                 Mage::log("max paid {$maxPaid}    ", null, 'custom.log');
                 Mage::log("product->getPrice()" . $_product->getPrice(), null, 'custom.log');
                 if ($numberOfProductsOrdered >= $requiredNumberOfProducts && $maxPaid >= $_product->getPrice()) {
                     Mage::log("stap 3   ", null, 'custom.log');
                     $this->productName = $_product->getName();
                     $this->feeMount = -1 * $_product->getPrice();
                     $couponDao->setCouponSavingInUse($couponSaving, $_product->getPrice(), $orderId);
                     Mage::log("Komt in aanmerking voor gratis product" . $this->productName . " price" . $this->feeMount, null, 'custom.log');
                     return true;
                 }
             } else {
                 $this->coupon = false;
             }
         }
     }
     Mage::log("Komt niet in aanmerking voor gratis product", null, 'custom.log');
     return false;
 }
Example #5
0
 public function setDiscount($observer)
 {
     try {
         $array = array();
         Mage::log(" we zijn in  setDiscount ", null, 'custom.log');
         $quote = $observer->getEvent()->getQuote();
         $quoteId = $quote->getId();
         $cartItems = $quote->getAllVisibleItems();
         $obj = new Excellence_Fee_Model_Fee();
         $customerId = Mage::getSingleton('customer/session')->getId();
         $discountAmount = 0;
         $discountDescription = "Voor spaarkaart voor";
         foreach ($cartItems as $item) {
             $productPrice = $item->getProduct()->getPrice();
             $store = Mage::app()->getStore('default');
             $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
             $taxClassId = $item->getData('tax_class_id');
             $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
             $tax = $percent * 0.01 * $productPrice;
             $totalAmount = $productPrice + $tax;
             Mage::log("mogelijk korting  {$totalAmount} , product prijs {$productPrice} en btw is {$tax} ", null, 'custom.log');
             $this->productId = $item->getProductId();
             $_product = Mage::getModel('catalog/product')->load($item->getProductId());
             $brand = $_product->getAttributeText('manufacturer');
             $couponDao = new CouponDao();
             $couponSaving = $couponDao->loadCouponSavingByOrderId($brand, $quoteId, $customerId);
             if ($couponSaving != null) {
                 $discountAmount = $couponSaving->getDiscountAmount();
                 Mage::log("discountAmount is {$discountAmount}", null, 'custom.log');
             } else {
                 Mage::log("discountAmount is 0", null, 'custom.log');
             }
             // if (!in_array($brand, $array)) {
             if ($couponSaving != null) {
                 Mage::log("setDiscount : stap voor 1   ", null, 'custom.log');
                 if ($couponSaving->getDiscountAmount() > 0) {
                     $discountDescription = "{$discountDescription} en  {$brand}";
                 } else {
                     $discountDescription = "{$discountDescription} voor {$brand}";
                 }
                 //$exist_amount = $couponSaving->getDiscountAmount();
                 //$discountAmount = $exist_amount;
                 array_push($array, $brand);
             } else {
                 if ($obj->canApply($item, $quoteId, $totalAmount)) {
                     Mage::log("setDiscount : stap voor 2   ", null, 'custom.log');
                     $brand = $obj->getBrand();
                     array_push($array, $brand);
                     Mage::log(" in canApply check for setDiscount  {$totalAmount}", null, 'custom.log');
                     $discountAmount = $discountAmount + $totalAmount;
                     if ($discountAmount > 0) {
                         $discountDescription = "{$discountDescription} en  {$brand}";
                     } else {
                         $discountDescription = "{$discountDescription} voor {$brand}";
                     }
                 }
             }
             //}
         }
         if ($quoteId) {
             Mage::log("setDiscount : stap 1   ", null, 'custom.log');
             if ($discountAmount > 0) {
                 Mage::log("setDiscount : stap 2   ", null, 'custom.log');
                 //we calculate the Ratio of taxes between GrandTotal & Discount Amount to know how much we need to remove.
                 $quote->setGrandTotal($quote->getGrandTotal() - $discountAmount)->setBaseGrandTotal($quote->getBaseGrandTotal() - $discountAmount)->setSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)->setBaseGrandTotal((double) $quote->getBaseGrandTotal())->setDiscountAmount($discountAmount)->setDiscountDescription($discountDescription)->setBaseDiscountAmount($discountAmount)->save();
                 $canAddItems = $quote->isVirtual() ? 'billing' : 'shipping';
                 foreach ($quote->getAllAddresses() as $address) {
                     $address->setSubtotal(0);
                     $address->setBaseSubtotal(0);
                     $address->setGrandTotal(0);
                     $address->setBaseGrandTotal(0);
                     $address->collectTotals();
                     if ($address->getAddressType() == $canAddItems) {
                         $address->setSubtotal((double) $quote->getSubtotal());
                         $address->setBaseSubtotal((double) $quote->getBaseSubtotal());
                         $address->setSubtotalWithDiscount((double) $quote->getSubtotalWithDiscount());
                         $address->setBaseSubtotalWithDiscount((double) $quote->getBaseSubtotalWithDiscount());
                         $address->setGrandTotal((double) $quote->getGrandTotal());
                         $address->setBaseGrandTotal((double) $quote->getBaseGrandTotal());
                         $address->setDiscountAmount(-$discountAmount);
                         $address->setDiscountDescription($discountDescription);
                         $address->setBaseDiscountAmount(-$discountAmount);
                         $address->setTaxAmount($tax);
                         $address->setBaseTaxAmount($tax);
                         $address->save();
                         Mage::log("setDiscount : stap 6   ", null, 'custom.log');
                     }
                     //end: if
                 }
                 //end: foreach
             }
         }
         Mage::log("setDiscount : stap 8   ", null, 'custom.log');
     } catch (Exception $e) {
         Mage::log("Set discount  exception " . $e, null);
     }
 }