1

Ok, trying to process a script, both PHP and JavaScript, where I am moving a particular content type NODE from one reference to another. This is the structure:

I have a PROJECT Inside each PROJECT are PAGES Inside each PAGE are CALLOUTS and Inside each CALLOUT are PRODUCTS.

What I want to do is take a PRODUCT from one CALLOUT to another CALLOUT. I am able to merge these, but now what I want to do is delete the first instance. An example:

I have PRODUCT AAG-794200 that is on PAGE 6 CALLOUT A. I am merging that PRODUCT with PAGE 6 CALLOUT B.

I can get the product to merge, but now I need to remove it from CALLOUT A. Here is my code:

$merge = explode(',', $merge); //Merge SKUs
$mpages = explode(',', $mpages); //Merge Pages
$mcallouts = explode(',', $mcallouts); //Merge Callouts
$mcallout_nid = explode(',', $mcallout_nid);  //Merge Current callout

$length = count($merge);
$e = 0;
while ($e < $length) {
    //Where is the SKU going to?
    $to_callout_letter = strtoupper($mcallouts[$e]);
    $to_page_num = $mpages[$e];
    $sku = $merge[$e];
    $from_callout = $mcallout_nid[$e];

    //Where is the SKU coming from?     
    $other_callout = node_load($from_callout);

    //Need page ID of current callout for project purposes
    $page_nid = $other_callout->field_page[0]['nid'];
    $page = node_load($page_nid);
    //Need the project NID
    $project_nid = $page->field_project[0]['nid'];

    //We need to get the NID of the page we are going to
    $page_nid = db_query('SELECT * FROM content_type_page WHERE field_page_order_value = "%d" and field_project_nid = "%d" ORDER BY vid DESC LIMIT 1', $to_page_num, $project_nid);

    $page_nid_res = db_fetch_array($page_nid);
    $to_page_nid = $page_nid_res['nid'];

    //We need to get the NID of the callout here
    $co_nid = db_query('SELECT * FROM content_type_callout WHERE field_identifier_value = "%s" and field_page_nid = "%d"', $to_callout_letter, $to_page_nid);
    $co_nid_res = db_fetch_array($co_nid);
    $to_callout_letter_nid = $co_nid_res['nid'];


    $callout = node_load($to_callout_letter_nid);
    $long = count($other_callout->field_skus);
    $deletecallout = array();
    foreach($other_callout->field_skus as $skus) {
        $s = 0;
        while ($s < $long) {
            if($skus['nid'] == $sku) {
                $callout->field_skus[] = $skus;
                $s++;
            }
            else {
                $deletecallout[] = $skus;
                $s++;
            }
        }
    }


    foreach($other_callout->field_images as $old_image) {
        $callout->field_images[] = $old_image;
    }
    foreach($other_callout->field_line_art as $old_image) {
        $callout->field_line_art[] = $old_image;
    }
    foreach($other_callout->field_swatches as $old_image) {
        $callout->field_swatches[] = $old_image;
    }

    $callout->field_copy_text[0]['value'] .= $other_callout->field_copy_text[0]['value'];
    $callout->field_notes[0]['value'] .= $other_callout->field_notes[0]['value'];
    $callout->field_image_notes[0]['value'] .= $other_callout->field_image_notes[0]['value'];
    $callout->field_status[0]['value'] = 'In Process';
    node_save($callout);

This causes the PRODUCTS to MERGE, but not delete the original.

Thanks for any help. I know it's something simple, and it will be a palm-to-face moment.

  • To clarify: is it the $f_callout (which is the same as $other_callout btw) node that you want to remove the references from? – kekkis Sep 24 '12 at 8:47
  • Yes... I actually solved this, and I realize now that $f_callout and $other_callout are the same. I was pulling from another module some of this code, so that's why it's duplicated. I have to perform a little clean up. I will answer below. – webdevsoup Sep 24 '12 at 12:10
0

So the answer to this was easier than I thought. I loaded the $other_callout node, and then unset the $key, utilizing the following code:

foreach($other_callout->field_skus as $key=>$value) {
if($value['nid'] == $sku) {
        $sku_rec = $value;
        $sku_rec_key = $key;
    continue;
    }
}

unset($other_callout->field_skus[$sku_rec_key]);

node_save($other_callout);

Thanks for the help guys, I appreciate it.

Drupal on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.