public function showSubAffiliateNetworkTable($customer_id, $referral, $parent_id, $i, $vgp) { if (!in_array($customer_id, $this->array_network_table)) { $this->array_network_table[] = $customer_id; $size = sizeof($this->getAffiliateParents($customer_id)); $customer_childs = $this->getAffiliateParents($customer_id); $customer = Mage::getModel('customer/customer')->load($customer_id); $name = $customer->getName(); $name_id = $customer->getId(); $email = $customer->getEmail(); $affiliateCustomer = Mage::getModel('affiliate/affiliatecustomers')->load($customer_id); $customerCommission = $affiliateCustomer->getTotalCommission(); $customerJoinedDate = $affiliateCustomer->getCustomerTime(); $customerStatus = $affiliateCustomer->getActive(); $code = $affiliateCustomer->getReferralCode(); $approve = $affiliateCustomer->getAutoapprove(); $name_id = $code; $sponsor = $affiliateCustomer->getReferralSponsor(); $customer_photo = $affiliateCustomer->getCustomerPhoto(); $customer_photo = $customer_photo ? $customer_photo : $this->getSkinUrl('images/avatar.png'); $affiliate_group = Mage::getModel('affiliate/affiliategroupmember')->getCollection()->addFieldToFilter('customer_id', Mage::getModel('customer/customer')->load($customer_id)->getId())->getFirstItem(); $affiliate_group = Mage::getModel('affiliate/affiliategroup')->getCollection()->addFieldToFilter('group_id', $affiliate_group['group_id'])->getFirstItem(); $dayFirst = date("Y-m-d 00:00:00", strtotime("first day of last month")); $dayLast = date("Y-m-d 23:59:59", strtotime("last day of last month")); $sale = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('updated_at', array('from' => $dayFirst, 'to' => $dayLast))->addAttributeToFilter('status', array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE))->addAttributeToFilter('customer_id', array('eq' => $customer_id)); $vp = 0; $vg = 0; foreach ($sale as $k => $order) { foreach ($order->getAllVisibleItems() as $i) { $v = $i->getData(); $product = Mage::getModel('catalog/product')->setStoreId($v['store_id'])->load($v['product_id']); $puntos = $product->getData('puntos'); $vp = $vp + $puntos * $v['qty_ordered']; } } // $month_date = strtotime(date('01/m/Y 00:00')); // $volume = Mage::getModel('affiliate/affiliatevolume')->getCollection() // ->addFieldToFilter('month_date', $month_date) // ->addFieldToFilter('customer_id', $customer_id) // ->getFirstItem() // ->getData(); // // $vp = isset($volume['vp']) ? $volume['vp'] : '0'; // $vg = isset($volume['vg']) ? $volume['vg'] : '0'; $group_name = $affiliate_group->getData(); $statusOptions = MW_Affiliate_Model_Statusactive::getOptionArray(); $color = '#166700'; if ($vp > 0) { if ($approve == 1) { $approve = 3; Mage::getSingleton('affiliate/affiliatecustomers')->load($customer_id)->setAutoapprove(3)->save(); } } else { $color = '#ff0000'; } if ($approve == 1) { $color = '#4F2F4F'; } if ($group_name['group_name'] == "CLIENTE PREFERENTE") { $color = '#FFFF33'; } $percentage = number_format($vp * 100 / $vgp, 2); //if($referral != '') { $this->_arrayResult[] = array('level' => $i, 'id' => $code, 'image' => $customer_photo, 'name' => $name, 'sponsor' => $sponsor, 'title' => $name, 'referral' => $referral, 'commission' => $customerCommission, 'joined_date' => $customerJoinedDate, 'parent' => $parent_id, 'rank' => $group_name['group_name'], 'code' => $code, 'personaactive' => 'true', 'status' => $statusOptions[$customerStatus], 'description' => "Rango: {$group_name['group_name']}", 'itemTitleColor' => $color, 'template' => 'contactTemplate', 'vp' => "VP: {$vp}", 'vg' => "VG: {$vg}", 'vgp' => "{$percentage}%"); //} //INACTIVES if (Mage::getStoreConfig('affiliate/config/inactives', Mage::app()->getStore()) == 1) { $inactive = Mage::getModel('affiliate/affiliatecustomers')->getCollection()->addFieldToFilter('customer_invited', $customer_id)->addFieldToFilter('active', 1); $inactive = $inactive->getData(); $c = 0; foreach ($inactive as $key => $value) { $c++; $name = Mage::getModel('customer/customer')->load($value['customer_id'])->getName(); $this->_arrayResult[] = array('level' => $i, 'parent' => $code, 'sponsor' => $value['referral_sponsor'], 'id' => $code . 'inactive-' . $c, 'code' => $code . 'inactive-' . $c, 'name' => $name, 'title' => $name, 'image' => $this->getSkinUrl('images/avatar.png'), 'personaactive' => 'true', 'description' => "Rango: -\n\nCodigo: -", 'itemTitleColor' => "#eee", 'vp' => "VP: 0", 'vg' => "VG: 0"); } } if ($size > 0) { $i = $i + 1; foreach ($customer_childs as $customer_child) { $this->showSubAffiliateNetworkTable($customer_child, $name, $name_id, $i, $vg); } } } }
public function networkInfo($customer_id, $parent_id, $i, $type, $firstDay, $lastDay, $leg) { $customer = Mage::getModel('customer/customer')->load($customer_id); $expired_package = Mage::getModel('affiliate/affiliateexpired')->load($customer_id); $affiliate = Mage::getModel('affiliate/affiliatecustomers')->load($customer_id); $code = $affiliate->getReferralCode(); $name = $customer->getName(); $sponsor = $affiliate->getReferralSponsor(); $invited = $affiliate->getCustomerInvited(); $sponsor_id = Mage::getModel('affiliate/affiliatecustomers')->getCollection()->addFieldToFilter('referral_code', $code)->getFirstItem()->getData("customer_invited"); $customerStatus = $affiliate->getActive(); $image = $affiliate->getCustomerPhoto() ? $affiliate->getCustomerPhoto() : Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . 'frontend/hs/default/images/avatar.png'; $group_member = Mage::getModel('affiliate/affiliategroupmember')->getCollection()->addFieldToFilter('customer_id', $customer_id)->getFirstItem(); $group = Mage::getModel('affiliate/affiliategroup')->getCollection()->addFieldToFilter('group_id', $group_member['group_id'])->getFirstItem(); $group_name = $group->getData('group_name'); $vp = 0; $vg = 0; $vpleft = 0; $vpright = 0; $constructor = 0; $color = '#166700'; $statusOptions = MW_Affiliate_Model_Statusactive::getOptionArray(); $array = array(); if ($i == 0) { $today = strtotime($lastDay); $last_pkt = strtotime($expired_package['expired_package'] . ' -1 Month'); $firstDay = date("Y-m-d 00:00:00", strtotime("first day of this month")); if ($expired_package['expired_package']) { if ($last_pkt <= $today) { $diff = abs($today - $last_pkt); $days = floor($diff / (60 * 60 * 24)); if ($days <= 30) { $firstDay = date("Y-m-d 00:00:00", $last_pkt); } } } } if (!($group_name == "CLIENTE PREFERENTE")) { $historial = Mage::getResourceModel('sales/order_status_history_collection')->addAttributeToSelect('parent_id')->addAttributeToFilter('main_table.status', array('eq' => 'complete'))->addAttributeToFilter('main_table.created_at', array('from' => $firstDay, 'to' => $lastDay))->addAttributeToFilter('main_table.entity_name', array('in' => array('invoice', 'shipment'))); if ($historial->getData('parent_id')) { $sale = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', array('eq' => $customer_id))->addAttributeToFilter('entity_id', array('in' => array($historial->getData('parent_id'))))->addAttributeToFilter('affiliate_network', array('eq' => $type)); foreach ($sale as $order) { $items = $order->getAllVisibleItems(); array_push($this->orders, array($order->getIncrementId())); foreach ($items as $item) { $single = $item->getData(); $puntos = Mage::getModel('catalog/product')->setStoreId($single['store_id'])->load($single['product_id'])->getData('puntos'); if ($single['product_type'] == 'bundle') { if (array_search($single['sku'], array('PTK-USA-010', 'PKT-USA-009', 'PKT-USA-008', 'PKT-USA-007', 'PKT-REC'))) { $puntos = $puntos; } else { $puntos = $puntos / 2; } } if ($order->getAffiliateSaleType() == 3) { //constructor $constructor = $puntos * $single['qty_ordered']; $puntos = $puntos * 0.25; } $vp = $vp + $puntos * $single['qty_ordered']; } } } if ($vp > 0) { if ($approve == 1) { $approve = 3; Mage::getSingleton('affiliate/affiliatecustomers')->load($customer_id)->setAutoapprove(3)->save(); } } else { $color = '#ff0000'; } if ($approve == 1) { $color = '#4F2F4F'; } $array = array('level' => $i, 'leg' => $leg, 'id' => $code, 'code' => $code, 'image' => $image, 'title' => $name, 'name' => $name, 'parent' => $parent_id, 'sponsor' => $sponsor, 'right' => $affiliate->getRightLeg() ? $affiliate->getRightLeg() : null, 'left' => $affiliate->getLeftLeg() ? $affiliate->getLeftLeg() : null, 'rank' => $group_name, 'status' => $statusOptions[$customerStatus], 'personaactive' => 'true', 'itemTitleColor' => $color, 'templateName' => 'contactTemplate', 'vp' => "{$vp}", 'vg' => "{$vg}", 'vleft' => "{$vpleft}", 'vpright' => "{$vpright}", 'constructor' => "{$constructor}"); } return $array; }
public function networkInfo($customer_id, $parent_id, $i, $type) { $customer = Mage::getModel('customer/customer')->load($customer_id); $affiliate = Mage::getModel('affiliate/affiliatecustomers')->load($customer_id); $code = $affiliate->getReferralCode(); $name = $customer->getName(); $sponsor = $affiliate->getReferralSponsor(); $invited = $affiliate->getCustomerInvited(); $sponsor_id = Mage::getModel('affiliate/affiliatecustomers')->getCollection()->addFieldToFilter('referral_code', $code)->getFirstItem()->getData("customer_invited"); $sponsor_name = Mage::getModel('customer/customer')->load($sponsor_id)->getName(); $referral_name = Mage::getModel('customer/customer')->load($invited)->getName(); $customerStatus = $affiliate->getActive(); $image = $affiliate->getCustomerPhoto() ? $affiliate->getCustomerPhoto() : Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . 'frontend/hs/default/images/avatar.png'; $group_member = Mage::getModel('affiliate/affiliategroupmember')->getCollection()->addFieldToFilter('customer_id', $customer_id)->getFirstItem(); $group = Mage::getModel('affiliate/affiliategroup')->getCollection()->addFieldToFilter('group_id', $group_member['group_id'])->getFirstItem(); $group_name = $group->getData('group_name'); $vp = 0; $vg = 0; $color = '#166700'; $statusOptions = MW_Affiliate_Model_Statusactive::getOptionArray(); $array = array(); if (!($group_name == "CLIENTE PREFERENTE")) { $firstDay = date("Y-m-d 00:00:00", strtotime("first day of this month")); $lastDay = date("Y-m-d 23:59:59", strtotime("last day of this month")); $sale = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('updated_at', array('from' => $firstDay, 'to' => $lastDay))->addAttributeToFilter('status', array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE))->addAttributeToFilter('customer_id', array('eq' => $customer_id))->addAttributeToFilter('affiliate_network', array('eq' => $type)); foreach ($sale as $order) { $items = $order->getAllVisibleItems(); foreach ($items as $item) { $single = $item->getData(); $puntos = Mage::getModel('catalog/product')->setStoreId($single['store_id'])->load($single['product_id'])->getData('puntos'); $vp = $vp + $puntos * $single['qty_ordered']; } } if ($vp > 0) { if ($approve == 1) { $approve = 3; Mage::getSingleton('affiliate/affiliatecustomers')->load($customer_id)->setAutoapprove(3)->save(); } } else { $color = '#ff0000'; } if ($approve == 1) { $color = '#4F2F4F'; } $array = array('level' => $i, 'id' => $code, 'code' => $code, 'image' => $image, 'title' => $name, 'name' => $name, 'referral' => "Colocado: " . $referral_name, 'sponsor_name' => "Directo: " . $sponsor_name, 'parent' => $parent_id, 'sponsor' => $sponsor, 'right' => $affiliate->getRightLeg() ? $affiliate->getRightLeg() : null, 'left' => $affiliate->getLeftLeg() ? $affiliate->getLeftLeg() : null, 'rank' => $group_name, 'status' => $statusOptions[$customerStatus], 'personaactive' => 'true', 'itemTitleColor' => $color, 'template' => 'contactTemplate', 'vp' => "{$vp}", 'vg' => "{$vg}"); } return $array; }
public function jsonAction() { if (Mage::getSingleton('customer/session')->isLoggedIn()) { $customerData = Mage::getSingleton('customer/session')->getCustomer(); $customer_id = $customerData->getId(); } $name = Mage::getModel('customer/customer')->load($customer_id)->getName(); $name_id = $customer_id; // Mage::getModel('customer/customer')->load($customer_id)->getId(); $affiliateCustomer = Mage::getModel('affiliate/affiliatecustomers')->load($customer_id); $customerCommission = $affiliateCustomer->getTotalCommission(); $customerJoinedDate = $affiliateCustomer->getCustomerTime(); $customerStatus = $affiliateCustomer->getActive(); $code = $affiliateCustomer->getReferralCode(); $customer_photo = $affiliateCustomer->getCustomerPhoto(); $customer_photo = $customer_photo ? $customer_photo : $this->getSkinUrl('images/avatar.png'); $affiliate_group = Mage::getModel('affiliate/affiliategroupmember')->getCollection()->addFieldToFilter('customer_id', $name_id)->getFirstItem(); $affiliate_group = Mage::getModel('affiliate/affiliategroup')->getCollection()->addFieldToFilter('group_id', $affiliate_group['group_id'])->getFirstItem(); $group_name = $affiliate_group->getData(); $statusOptions = MW_Affiliate_Model_Statusactive::getOptionArray(); $newArray = array('level' => 0, 'id' => $code, 'image' => $customer_photo, 'name' => $name, 'title' => $name, 'commission' => $customerCommission, 'joined_date' => $customerJoinedDate, 'code' => $code, 'parent' => null, 'personaactive' => 'true', 'rank' => $group_name['group_name'], 'status' => $statusOptions[$customerStatus], 'description' => "Rango: {$group_name['group_name']}\n\nCodigo:{$code}"); //echo '<pre>';print_R($newArray);echo '</pre>'; }
public function showSubAffiliateNetworkTable($customer_id, $referral, $i) { if (!in_array($customer_id, $this->array_network_table)) { $this->array_network_table[] = $customer_id; $size = sizeof($this->getAffiliateParents($customer_id)); $customer_childs = $this->getAffiliateParents($customer_id); $name = Mage::getModel('customer/customer')->load($customer_id)->getName(); $email = Mage::getModel('customer/customer')->load($customer_id)->getEmail(); $affiliateCustomer = Mage::getModel('affiliate/affiliatecustomers')->load($customer_id); $customerCommission = $affiliateCustomer->getTotalCommission(); $customerJoinedDate = $affiliateCustomer->getCustomerTime(); $customerStatus = $affiliateCustomer->getActive(); $statusOptions = MW_Affiliate_Model_Statusactive::getOptionArray(); if ($referral != '') { $this->_arrayResult[] = array('level' => $i, 'name' => $name, 'email' => $email, 'referral' => $referral, 'commission' => $customerCommission, 'joined_date' => $customerJoinedDate, 'status' => $statusOptions[$customerStatus]); } if ($size > 0) { $i = $i + 1; foreach ($customer_childs as $customer_child) { $this->showSubAffiliateNetworkTable($customer_child, $name, $i); } } } }