Exemplo n.º 1
0
 function getGroupedDiscount(\SoftoneBundle\Entity\Customer $customer)
 {
     $rules = $customer->getCustomergroup()->loadCustomergrouprules()->getRules();
     $sortorder = 0;
     foreach ($rules as $rule) {
         if ($rule->validateRule($this) and $sortorder <= $rule->getSortorder()) {
             $sortorder = $rule->getSortorder();
             $disount = $rule->getVal();
             $price = $rule->getPrice();
         }
     }
     return $disount > 0 ? $disount : $price;
 }
 /**
  * @Route("/customer/retrieve")
  */
 function retrieveSoftoneData($params = array())
 {
     $this->retrieveCustomer();
     $params["list"] = 'partsbox';
     $params = array("softone_object" => "CUSTOMER", "eav_model" => "customer", "model" => "Customer", "list" => "monitor");
     set_time_limit(100000);
     ini_set('memory_limit', '2256M');
     $softone = new Softone();
     $em = $this->getDoctrine()->getManager();
     $fields = $em->getClassMetadata('SoftoneBundle\\Entity\\Customer')->getFieldNames();
     $date = "2016-02-01";
     $filters = "CUSTOMER.UPDDATE=" . $date . "&CUSTOMER.UPDDATE_TO=" . date("Y-m-d");
     $datas = $softone->retrieveData($params["softone_object"], $params["list"], $filters);
     foreach ($datas as $data) {
         $data = (array) $data;
         $zoominfo = $data["zoominfo"];
         $info = explode(";", $zoominfo);
         $entity = $this->getDoctrine()->getRepository($this->repository)->findOneBy(array("reference" => (int) $info[1]));
         if (@$entity->id == 0) {
             $entity = new Customer();
             $dt = new \DateTime("now");
             $entity->setTs($dt);
             $entity->setField("reference", (int) $info[1]);
             //$entity->setCustomerInsdate($dt);
             //$entity->setCustomerUpddate($dt);
             $entity->setCreated($dt);
             $entity->setModified($dt);
         }
         $this->flushpersist($entity);
         $q = array();
         foreach ($data as $identifier => $val) {
             $imporetedData[strtolower($identifier)] = addslashes($val);
             $ad = strtolower(str_replace(strtolower($params["softone_object"]) . "_", "", $identifier));
             $baz = strtolower($params["softone_object"]) . ucwords(str_replace("_", " ", $ad));
             //echo $baz."<BR>";
             if (in_array($baz, $fields)) {
                 $q[] = "`" . strtolower($identifier) . "` = '" . addslashes($val) . "'";
                 //$entity->setField($baz, $val);
             }
         }
         @($entity_id = (int) $entity->id);
         if (@$entity_id > 0) {
             $sql = "update softone_customer set " . implode(",", $q) . " where id = '" . $entity_id . "'";
             //echo $sql."<BR>";
             $em->getConnection()->exec($sql);
         }
         //break;
     }
     $datas = $softone->getCustomerAddresses();
     $sql = "truncate softone_customeraddress";
     $em->getConnection()->exec($sql);
     $fields = $em->getClassMetadata('SoftoneBundle\\Entity\\Customeraddress')->getFieldNames();
     //print_r($datas);
     if (@$datas->data) {
         foreach ($datas->data as $data) {
             $data = (array) $data;
             $customer = $this->getDoctrine()->getRepository($this->repository)->findOneBy(array("reference" => (int) $data["TRDR"]));
             $entity = new \SoftoneBundle\Entity\Customeraddress();
             $entity->setCustomer($customer);
             $entity->setReference($data["TRDR"]);
             $this->flushpersist($entity);
             $q = array();
             foreach ($data as $identifier => $val) {
                 if (in_array(strtolower($identifier), $fields)) {
                     $q[] = "`" . strtolower($identifier) . "` = '" . addslashes($val) . "'";
                     //$entity->setField($baz, $val);
                 }
             }
             @($entity_id = (int) $entity->id);
             $sql = "update softone_customeraddress set " . implode(",", $q) . " where id = '" . $entity_id . "'";
             $em->getConnection()->exec($sql);
             //echo $sql . "<BR>";
         }
     }
     exit;
 }