Пример #1
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_product = new org_openpsa_products_product_dba();
     $this->_request_data['up'] = $controller->formmanager->get_value('productGroup');
     $this->_product->productGroup = $this->_request_data['up'];
     if (!$this->_product->create()) {
         debug_print_r('We operated on this object:', $this->_product);
         throw new midcom_error("Failed to create a new product under product group #{$this->_request_data['up']}. Error: " . midcom_connection::get_error_string());
     }
     return $this->_product;
 }
Пример #2
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 private function _create_product($title, $productgroup)
 {
     $product = new org_openpsa_products_product_dba();
     $product->productGroup = $productgroup;
     $product->title = $title;
     if (!$product->create()) {
         debug_print_r('We operated on this object:', $product);
         return null;
     }
     // Generate URL name
     if ($product->code == '') {
         $product->code = midcom_helper_misc::generate_urlname_from_string($product->title);
         $tries = 0;
         $maxtries = 999;
         while (!$product->update() && $tries < $maxtries) {
             $product->code = midcom_helper_misc::generate_urlname_from_string($product->title);
             if ($tries > 0) {
                 // Append an integer if products with same name exist
                 $product->code .= sprintf("-%03d", $tries);
             }
             $tries++;
         }
     }
     $product->parameter('midcom.helper.datamanager2', 'schema_name', $this->_config->get('api_products_schema'));
     return $product;
 }
Пример #3
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_productlink = new org_openpsa_products_product_link_dba();
     if (isset($_POST['productGroup'])) {
         $this->_request_data['up'] = (int) $_POST['productGroup'];
     }
     $this->_productlink->productGroup = $this->_request_data['up'];
     if (isset($_POST['product'])) {
         $this->_request_data['product'] = (int) $_POST['product'];
     }
     $this->_productlink->product = $this->_request_data['product'];
     if (!$this->_productlink->create()) {
         debug_print_r('We operated on this object:', $this->_productlink);
         throw new midcom_error("Failed to create a new productlink under product group #{$this->_request_data['up']}. Error: " . midcom_connection::get_error_string());
     }
     return $this->_productlink;
 }
Пример #4
0
 public function testCRUD()
 {
     $code = 'PRODUCT-TEST-' . __CLASS__ . time();
     $product = new org_openpsa_products_product_dba();
     $product->code = $code;
     $product->productGroup = self::$_group->id;
     midcom::get('auth')->request_sudo('org.openpsa.products');
     $stat = $product->create();
     $this->assertTrue($stat);
     $this->register_object($product);
     $parent = $product->get_parent();
     $this->assertEquals($parent->guid, self::$_group->guid);
     $product->title = 'TEST TITLE';
     $stat = $product->update();
     $this->assertTrue($stat);
     $this->assertEquals($product->title, 'TEST TITLE');
     $stat = $product->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
Пример #5
0
 private function _import_product($productdata)
 {
     $data =& $this->_request_data;
     // Convert fields from latin-1 to MidCOM charset (usually utf-8)
     foreach ($productdata as $key => $value) {
         // FIXME: It would be immensely more efficient to do this per-file or even per row rather than per field
         $productdata[$key] = $this->_charset_convert($value);
     }
     $product = null;
     $new = false;
     // GUID has precedence
     if (isset($productdata['GUID']) && !empty($productdata['GUID'])) {
         $product = new org_openpsa_products_product_dba($productdata['GUID']);
         if ($product->guid != $productdata['GUID']) {
             // Could not fetch correct product
             unset($product);
         }
     } else {
         if (isset($productdata['code'])) {
             // FIXME: the product group should be taken into account here, codes are quaranteed to be unique only within the group
             $qb = org_openpsa_products_product_dba::new_query_builder();
             $qb->add_constraint('code', '=', (string) $productdata['code']);
             $products = $qb->execute();
             if (count($products) > 0) {
                 // Match found, use it
                 $product = $products[0];
             }
         }
     }
     if (!$product) {
         // We didn't have group matching the code in DB. Create a new one.
         $product = new org_openpsa_products_product_dba();
         $product->productGroup = $data['new_products_product_group'];
         if (!$product->create()) {
             debug_add("Failed to create product, reason " . midcom_connection::get_error_string());
             $this->_request_data['import_status']['failed_create']++;
             return false;
             // This will skip to next
         }
         $product->set_parameter('midcom.helper.datamanager2', 'schema_name', $data['schema']);
         $new = true;
     }
     // Map products without group to the "new products" group
     if (empty($product->productGroup) && !empty($data['new_products_product_group'])) {
         $product->productGroup = $data['new_products_product_group'];
     }
     if (!$this->_datamanager_process($productdata, $product)) {
         if ($new) {
             $product->delete();
             $this->_request_data['import_status']['failed_create']++;
         } else {
             $this->_request_data['import_status']['failed_update']++;
         }
         return false;
     }
     $this->_products_processed[$product->code] = $product;
     if ($new) {
         $this->_request_data['import_status']['created']++;
     } else {
         $this->_request_data['import_status']['updated']++;
     }
     return $product;
 }