Skip to content

Commit

Permalink
Merge pull request #394 from bugfolder/336_fix_url_aliases
Browse files Browse the repository at this point in the history
Issue #336: Fix disappearing product URL aliases
  • Loading branch information
bugfolder authored Nov 21, 2022
2 parents 88c3eaf + 22dfa4f commit 190f042
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
16 changes: 10 additions & 6 deletions uc_cart/uc_cart.controller.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class UcCartItemController extends EntityPlusController {
foreach ($product as $key => $value) {
$item->$key = $value;
}
// UcCartItem should not have a path (inherited from the node) so that
// path module doesn't try to update the node's alias.
unset($item->path);
}
$item->module = $item->data['module'];
}
Expand Down Expand Up @@ -67,6 +70,11 @@ class UcCartItem extends Entity {
*/
public $cart_item_id;

function __construct(array $values = array()) {
parent::__construct($values);
unset($this->path);
}

/**
* Implements EntityInterface::id().
*/
Expand All @@ -92,11 +100,7 @@ class UcCartItem extends Entity {
* Implements EntityInterface::uri().
*/
public function uri() {
// Since uc_order_product entities are derived from nodes, we return the uri
// of its "parent" node.
return array(
'path' => 'node/' . $this->nid,
'options' => array(),
);
// Only used internally, so doesn't have a URI.
return NULL;
}
}
19 changes: 13 additions & 6 deletions uc_order/uc_order.entity.inc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ class UcOrder extends Entity {
*/
class UcOrderProduct extends Entity {

/**
* Constructor.
*/
public function __construct(array $values) {
parent::__construct($values);

// UcOrderProduct should not have a path set; if it does, pathauto tries to
// update an alias for the entity.
unset($this->path);
}

/**
* The node ID.
*
Expand Down Expand Up @@ -156,11 +167,7 @@ class UcOrderProduct extends Entity {
* Implements EntityInterface::uri().
*/
public function uri() {
// Since uc_order_product entities are derived from nodes, we return the uri
// of its "parent" node.
return array(
'path' => 'node/' . $this->nid,
'options' => array(),
);
// UcOrderProduct is only used internally, so doesn't have a URI.
return NULL;
}
}
11 changes: 11 additions & 0 deletions uc_order/uc_order.module
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,14 @@ function uc_order_product_save($order_id, $product) {
$product->is_new = TRUE;
}

// It's possible that a contrib or custom module updated the order's products
// and assigned the product's path variable from the node. In case that
// happened, we'll unset it here so that path module doesn't try to update the
// node's alias via path_entity_update().
unset($product->path);

// Note that $product can be a UcOrderProduct or a UcCartItem, but we use
// the UcOrderProductController class in either case.
return entity_get_controller('uc_order_product')->save($product);
}

Expand Down Expand Up @@ -1184,6 +1192,9 @@ function uc_order_product_revive($products, $published = TRUE) {
$product->$key = $value;
}
}
// uc_order_product entities should not have a path (inherited from the
// node) so that path module doesn't try to update the node's alias.
unset($product->path);
// Order products are always variants.
$product->variant = TRUE;
}
Expand Down

0 comments on commit 190f042

Please sign in to comment.