function run($request)
 {
     $customerGroup = EcommerceRole::get_customer_group();
     if ($customerGroup) {
         $allCombos = DB::query("\n\t\t\t\tSELECT \"Group_Members\".\"ID\", \"Group_Members\".\"MemberID\", \"Group_Members\".\"GroupID\"\n\t\t\t\tFROM \"Group_Members\"\n\t\t\t\tWHERE \"Group_Members\".\"GroupID\" = " . $customerGroup->ID . ";");
         //make an array of all combos
         $alreadyAdded = array();
         $alreadyAdded[-1] = -1;
         if ($allCombos) {
             foreach ($allCombos as $combo) {
                 $alreadyAdded[$combo["MemberID"]] = $combo["MemberID"];
             }
         }
         $unlistedMembers = Member::get()->exclude(array("ID" => $alreadyAdded))->innerJoin("Order", "\"Order\".\"MemberID\" = \"Member\".\"ID\"");
         //add combos
         if ($unlistedMembers->count()) {
             $existingMembers = $customerGroup->Members();
             foreach ($unlistedMembers as $member) {
                 $existingMembers->add($member);
                 DB::alteration_message("Added member to customers: " . $member->Email, "created");
             }
         }
     } else {
         DB::alteration_message("NO customer group found", "deleted");
     }
 }
コード例 #2
0
 function run($request)
 {
     $customerGroup = EcommerceRole::get_customer_group();
     if ($customerGroup) {
         $allCombos = DB::query("\n\t\t\t\tSELECT \"Group_Members\".\"ID\", \"Group_Members\".\"MemberID\", \"Group_Members\".\"GroupID\"\n\t\t\t\tFROM \"Group_Members\"\n\t\t\t\tWHERE \"Group_Members\".\"GroupID\" = " . $customerGroup->ID . ";");
         //make an array of all combos
         $alreadyAdded = array();
         $alreadyAdded[-1] = -1;
         if ($allCombos) {
             foreach ($allCombos as $combo) {
                 $alreadyAdded[$combo["MemberID"]] = $combo["MemberID"];
             }
         }
         $unlistedMembers = DataObject::get("Member", $where = "\"Member\".\"ID\" NOT IN (" . implode(",", $alreadyAdded) . ")", $sort = "", $join = "INNER JOIN \"Order\" ON \"Order\".\"MemberID\" = \"Member\".\"ID\"");
         //add combos
         if ($unlistedMembers) {
             $existingMembers = $customerGroup->Members();
             foreach ($unlistedMembers as $member) {
                 $existingMembers->add($member);
                 DB::alteration_message("Added member to customers: " . $member->Email, "created");
             }
         }
     } else {
         DB::alteration_message("NO customer group found", "deleted");
     }
 }
コード例 #3
0
 /**
  * standard SS method
  * Make sure the member is added as a customer
  */
 public function onAfterWrite()
 {
     $customerGroup = EcommerceRole::get_customer_group();
     if ($customerGroup) {
         $existingMembers = $customerGroup->Members();
         if ($existingMembers) {
             $existingMembers->add($this->owner);
         }
     }
 }
コード例 #4
0
 function run($request)
 {
     $customerGroup = EcommerceRole::get_customer_group();
     $customerPermissionCode = EcommerceConfig::get("EcommerceRole", "customer_permission_code");
     if (!$customerGroup) {
         $customerGroup = new Group();
         $customerGroup->Code = EcommerceConfig::get("EcommerceRole", "customer_group_code");
         $customerGroup->Title = EcommerceConfig::get("EcommerceRole", "customer_group_name");
         $customerGroup->write();
         Permission::grant($customerGroup->ID, $customerPermissionCode);
         DB::alteration_message(EcommerceConfig::get("EcommerceRole", "customer_group_name") . ' Group created', "created");
     } elseif (DB::query("SELECT * FROM \"Permission\" WHERE \"GroupID\" = '" . $customerGroup->ID . "' AND \"Code\" LIKE '" . $customerPermissionCode . "'")->numRecords() == 0) {
         Permission::grant($customerGroup->ID, $customerPermissionCode);
         DB::alteration_message(EcommerceConfig::get("EcommerceRole", "customer_group_name") . ' permissions granted', "created");
     }
     $customerGroup = EcommerceRole::get_customer_group();
     if (!$customerGroup) {
         user_error("could not create user group");
     } else {
         DB::alteration_message(EcommerceConfig::get("EcommerceRole", "customer_group_name") . ' is ready for use', "created");
     }
     $adminGroup = EcommerceRole::get_admin_group();
     $adminCode = EcommerceConfig::get("EcommerceRole", "admin_group_code");
     $adminName = EcommerceConfig::get("EcommerceRole", "admin_group_name");
     $adminPermissionCode = EcommerceConfig::get("EcommerceRole", "admin_permission_code");
     $adminRoleTitle = EcommerceConfig::get("EcommerceRole", "admin_role_title");
     if (!$adminGroup) {
         $adminGroup = new Group();
         $adminGroup->Code = $adminCode;
         $adminGroup->Title = $adminName;
         $adminGroup->write();
         Permission::grant($adminGroup->ID, $adminPermissionCode);
         DB::alteration_message($adminName . ' Group created', "created");
     } elseif (DB::query("SELECT * FROM \"Permission\" WHERE \"GroupID\" = '" . $adminGroup->ID . "' AND \"Code\" LIKE '" . $adminPermissionCode . "'")->numRecords() == 0) {
         Permission::grant($adminGroup->ID, $adminPermissionCode);
         DB::alteration_message($adminName . ' permissions granted', "created");
     }
     $permissionRole = DataObject::get_one("PermissionRole", "\"Title\" = '" . $adminRoleTitle . "'");
     if (!$permissionRole) {
         $permissionRole = new PermissionRole();
         $permissionRole->Title = $adminRoleTitle;
         $permissionRole->OnlyAdminCanApply = true;
         $permissionRole->write();
     }
     if ($permissionRole) {
         $permissionArray = EcommerceConfig::get("EcommerceRole", "admin_role_permission_codes");
         if (is_array($permissionArray) && count($permissionArray) && $permissionRole) {
             foreach ($permissionArray as $permissionCode) {
                 $permissionRoleCode = DataObject::get_one("PermissionRoleCode", "\"Code\" = '{$permissionCode}'");
                 if (!$permissionRoleCode) {
                     $permissionRoleCode = new PermissionRoleCode();
                     $permissionRoleCode->Code = $permissionCode;
                     $permissionRoleCode->RoleID = $permissionRole->ID;
                     $permissionRoleCode->write();
                 }
             }
         }
         if ($adminGroup) {
             $existingGroups = $permissionRole->Groups();
             $existingGroups->add($adminGroup);
         }
     }
 }
 private function addspecialprice()
 {
     $task = new EcommerceTaskCreateMemberGroups();
     $task->run(false);
     $customerGroup = EcommerceRole::get_customer_group();
     if (!$customerGroup) {
         die("could not create customer group");
     }
     $group = new Group();
     $group->Title = "Discount Customers";
     $group->Code = "discountcustomers";
     $group->ParentID = $customerGroup->ID;
     $group->write();
     $member = new Member();
     $member->FirstName = 'Bob';
     $member->Surname = 'Jones';
     $member->Email = '*****@*****.**';
     $member->Password = '******';
     $member->write();
     $member->Groups()->add($group);
     $products = Product::get()->where("ClassName = 'Product'")->sort("RAND()")->limit(2);
     $this->addExamplePages(4, "Special price for particular customers", $products);
     $i = 0;
     foreach ($products as $product) {
         $i++;
         $complexObjectPrice = new ComplexPriceObject();
         if ($i == 1) {
             $complexObjectPrice->Price = $product->Price - 1.5;
         } elseif ($i == 2) {
             $complexObjectPrice->Percentage = 10;
             $complexObjectPrice->Reduction = 2.5;
         } else {
             $complexObjectPrice->Price = $product->Price - 1.5;
             $complexObjectPrice->Percentage = 10;
             $complexObjectPrice->Reduction = 2.5;
         }
         $complexObjectPrice->From = date("Y-m-d h:n:s", strtotime("now"));
         $complexObjectPrice->Until = date("Y-m-d h:n:s", strtotime("next year"));
         $complexObjectPrice->ProductID = $product->ID;
         $complexObjectPrice->write();
         $complexObjectPrice->Groups()->add($group);
         $product->Content = "<p><a href=\"Security/login/?BackURL=" . $product->Link() . "\">Login</a> as bob@silverstripe-ecommerce.com, password: test123 to get a special price. You can then <a href=\"Security/logout/?BackURL=" . $product->Link() . "\">log out</a> again to see the original price.</p>";
         $this->addToTitle($product, "member price", true);
     }
     $variations = ProductVariation::get()->where("ClassName = 'ProductVariation'")->sort("RAND()")->limit(2);
     $i = 0;
     foreach ($variations as $variation) {
         $i++;
         $complexObjectPrice = new ComplexPriceObject();
         if ($i == 1) {
             $complexObjectPrice->Price = $product->Price - 1.5;
         } elseif ($i == 2) {
             $complexObjectPrice->Percentage = 10;
             $complexObjectPrice->Reduction = 2.5;
         } else {
             $complexObjectPrice->Price = $product->Price - 1.5;
             $complexObjectPrice->Percentage = 10;
             $complexObjectPrice->Reduction = 2.5;
         }
         $complexObjectPrice->Price = $variation->Price - 1.5;
         $complexObjectPrice->From = date("Y-m-d h:n:s", strtotime("now"));
         $complexObjectPrice->Until = date("Y-m-d h:n:s", strtotime("next year"));
         $complexObjectPrice->ProductVariationID = $variation->ID;
         $complexObjectPrice->write();
         $complexObjectPrice->Groups()->add($group);
         $product = $variation->Product();
         $this->addExamplePages(4, "Special price for particular customers for product variations {$i}", $product);
         $product->Content = "<p><a href=\"Security/login/?BackURL=" . $product->Link() . "\">Login</a> as bob@jones.com, password: test123 to get a special price</p>";
         $this->addToTitle($product, "member price", true);
     }
 }