Cart::update

@param string $sku
@param array  $item

@return bool
197590
public function update($sku, array $item)
    {
        if ($this->offsetExists($sku)) {
            $item = array_merge($this->offsetGet($sku), $item);

            // update sub-total
            $item[ 'subTotal' ][ 'price' ] = $item[ 'price' ] * $item[ 'quantity' ];
            $item[ 'subTotal' ][ 'weight' ] = $item[ 'weight' ] * $item[ 'quantity' ];

            $this->storage[ $sku ] = $item;

            return true;
        }

        return false;
    }
88624
private function acquireLock(string $sku) {
    $lock_key = self::class . ':' . $sku;
    do {
      $lock_acquired = $this->lock->acquire($lock_key);

      // Sleep for half a second before trying again.
      if (!$lock_acquired) {
        usleep(500000);
      }
    } while (!$lock_acquired);
  }
1231860
protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile)
    {
        $changed = false;
        $responses = $item->getResponses();

        foreach ($responses as $response) {

            $responseIdentifier = $response->attr('identifier');
            $rules              = $response->getFeedbackRules();

            foreach ($rules as $rule) {
                $modalFeedbacks = array();
                if ($rule->getFeedbackThen()) {
                    $modalFeedbacks[] = $rule->getFeedbackThen();
                }
                if ($rule->getFeedbackElse()) {
                    $modalFeedbacks[] = $rule->getFeedbackElse();
                }
                foreach ($modalFeedbacks as $modalFeedback) {
                    $feedbackXml = simplexml_load_string($modalFeedback->toQti());
                    if ($feedbackXml->div[0] && $feedbackXml->div[0]['class'] && preg_match('/^x-tao-wrapper/',
                            $feedbackXml->div[0]['class'])) {
                        //the item body has not already been wrapped by the new wrapper <div class="x-tao-wrapper w-tao-relatedOutcome-{{response.identifier}}">
                        continue;
                    }
                    $message = $modalFeedback->getBody()->getBody();
                    $modalFeedback->getBody()->edit('<div class="x-tao-wrapper x-tao-relatedOutcome-'.$responseIdentifier.'">'.$message.'</div>',
                        true);
                    $changed = true;
                }
            }
        }

        return $changed;
    }
78783
public function deriveProductTree(SKU $sku) {
    static $cache = [];

    if (isset($cache[$sku->language()->getId()], $cache[$sku->language()->getId()][$sku->id()])) {
      return $cache[$sku->language()->getId()][$sku->id()];
    }

    $tree = [
      'parent' => $sku,
      'products' => self::getChildren($sku),
      'combinations' => [],
    ];

    $configurables = unserialize(
      $sku->get('field_configurable_attributes')->getString()
    );

    $tree['configurables'] = [];
    foreach ($configurables as $configurable) {
      $tree['configurables'][$configurable['code']] = $configurable;
    }

    $configurable_codes = array_keys($tree['configurables']);

    foreach ($tree['products'] ?? [] as $sku_code => $sku_entity) {
      $attributes = $sku_entity->get('attributes')->getValue();
      $attributes = array_column($attributes, 'value', 'key');
      foreach ($configurable_codes as $code) {
        $value = $attributes[$code] ?? '';

        if (empty($value)) {
          continue;
        }

        $tree['combinations']['by_sku'][$sku_code][$code] = $value;
      }
    }

    /** @var \Drupal\acm_sku\CartFormHelper $helper */
    $helper = \Drupal::service('acm_sku.cart_form_helper');

    $configurable_weights = $helper->getConfigurableAttributeWeights(
      $sku->get('attribute_set')->getString()
    );

    // Sort configurables based on the config.
    uasort($tree['configurables'], function ($a, $b) use ($configurable_weights) {
      return $configurable_weights[$a['code']] - $configurable_weights[$b['code']];
    });

    $tree['options'] = Configurable::recursiveConfigurableTree(
      $tree,
      $tree['configurables']
    );

    $cache[$sku->language()->getId()][$sku->id()] = $tree;

    return $tree;
  }
42948
protected function recordEcommerceItems($goal, $items)
    {
        $itemInCartBySku = array();
        foreach ($items as $item) {
            $itemInCartBySku[$item[0]] = $item;
        }

        $itemsInDb = $this->getModel()->getAllItemsCurrentlyInTheCart($goal, self::ITEM_IDORDER_ABANDONED_CART);

        // Look at which items need to be deleted, which need to be added or updated, based on the SKU
        $skuFoundInDb = $itemsToUpdate = array();

        foreach ($itemsInDb as $itemInDb) {
            $skuFoundInDb[] = $itemInDb['idaction_sku'];

            // Ensure price comparisons will have the same assumption
            $itemInDb['price'] = $this->getRevenue($itemInDb['price']);
            $itemInDbOriginal = $itemInDb;
            $itemInDb = array_values($itemInDb);

            // Cast all as string, because what comes out of the fetchAll() are strings
            $itemInDb = $this->getItemRowCast($itemInDb);

            //Item in the cart in the DB, but not anymore in the cart
            if (!isset($itemInCartBySku[$itemInDb[0]])) {
                $itemToUpdate = array_merge($itemInDb,
                    array('deleted'                => 1,
                          'idorder_original_value' => $itemInDbOriginal['idorder_original_value']
                    )
                );

                $itemsToUpdate[] = $itemToUpdate;
                Common::printDebug("Item found in the previous Cart, but no in the current cart/order");
                Common::printDebug($itemToUpdate);
                continue;
            }

            $newItem = $itemInCartBySku[$itemInDb[0]];
            $newItem = $this->getItemRowCast($newItem);

            if (count($itemInDb) != count($newItem)) {
                Common::printDebug("ERROR: Different format in items from cart and DB");
                throw new Exception(" Item in DB and Item in cart have a different format, this is not expected... " . var_export($itemInDb, true) . var_export($newItem, true));
            }
            Common::printDebug("Item has changed since the last cart. Previous item stored in cart in database:");
            Common::printDebug($itemInDb);
            Common::printDebug("New item to UPDATE the previous row:");
            $newItem['idorder_original_value'] = $itemInDbOriginal['idorder_original_value'];
            Common::printDebug($newItem);
            $itemsToUpdate[] = $newItem;
        }

        // Items to UPDATE
        $this->updateEcommerceItems($goal, $itemsToUpdate);

        // Items to INSERT
        $itemsToInsert = array();
        foreach ($items as $item) {
            if (!in_array($item[0], $skuFoundInDb)) {
                $itemsToInsert[] = $item;
            }
        }

        $this->insertEcommerceItems($goal, $itemsToInsert);
    }
4772
public function addItem( $model, $item, $config = [] ) {

		$cartItemService = Yii::$app->factory->get( 'cartItemService' );

		$item->cartId = $model->id;

		// Remove in case it's not required
		if( isset( $item->id ) && $item->id > 0 && !$item->keep ) {

			$cartItemService->delete( $item );
		}
		else if( $item->keep ) {

			// Create
			if( !isset( $item->id ) || $item->id <= 0 ) {

				return $cartItemService->create( $item );
			}
			// update
			else {

				return $cartItemService->update( $item, $config );
			}
		}

		return false;
	}
765899
public function update(CartItem $cartitem, UpdateCartItemRequest $request)
    {
        $this->cartitem->update($cartitem, $request->all());

        return redirect()->route('admin.cart.cartitem.index')
            ->withSuccess(trans('core::core.messages.resource updated', ['name' => trans('cart::cartitems.title.cartitems')]));
    }
110053
private function releaseLock(string $sku) {
    $lock_key = self::class . ':' . $sku;
    $this->lock->release($lock_key);
  }
1096225
public function getBySku(SKU $SKU): Product
    {
        if (isset($this->products[(string) $SKU])) {
            return $this->products[(string) $SKU];
        }

        throw ProductNotFound::bySku($SKU);
    }
672887
public function save($item, bool $update = false)
    {
        if ($update || $item->id) {
            if ($item->id) {
                $field = Craft::$app->fields->getFieldById($item->id);
            } else {
                $field = Craft::$app->fields->getFieldByHandle($item->handle);
            }
            if ($field) {
                if (\get_class($item) !== \get_class($field)) {
                    $error = Architect::t('Type does not match existing type: "{fieldType}".', ['fieldType' => \get_class($field) ]);
                    $item->addError('type', $error);
                    return false;
                }
            }
        }
        return Craft::$app->fields->saveField($item);
    }
1252310
public function update($product_sku, $uid)
    {
        $product = Subbly::api('subbly.product')->find($product_sku);

        if (!Input::hasFile('product_image')) {
            return $this->jsonErrorResponse('"product_image" is required.');
        }

        $productImage = Subbly::api('subbly.product_image')->update($uid, array(
            'image' => Input::file('product_image'),
        ));

        return $this->jsonResponse(array(
            'product_image' => $productImage,
        ),
        array(
            'status' => array(
                'code'    => 200,
                'message' => 'ProductImage updated',
            ),
        ));
    }
968796
public function remove($sku)
    {
        $product = $this->pick($sku);

        $this->products->remove($sku);
    }
844895
public function push($item)
    {
        if (!is_array($item)) {
            $this->items = array_merge($this->items, [$item]);
            return $this;
        }
        $this->items = array_merge($this->items, $item);
        return $this;
    }
242134
public function update(
        $sku,
        array $attributes,
        array $images = [],
        array $categories = [],
        array $specifications = [],
        array $variations = [],
        array $variationAttributes = []
    ) {
        $transformer = new UpdateTransformer(
            $sku,
            $attributes,
            $images,
            $categories,
            $specifications,
            $variations,
            $variationAttributes
        );

        $body = $transformer->output();

        /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */
        $responseHandler = $this->service()->put($this->baseUrlPath($sku), $body);
        return $responseHandler;
    }
36642
public function update($item)
    {
        $item['updated'] = gettime('Y-m-d H:i:s');
        $item['options'] = encodeOptions($item['options']);
        $item['title'] = Eresus_CMS::getLegacyKernel()->db->escape($item['title']);
        $item['caption'] = Eresus_CMS::getLegacyKernel()->db->escape($item['caption']);
        $item['description'] = Eresus_CMS::getLegacyKernel()->db->escape($item['description']);
        $item['hint'] = Eresus_CMS::getLegacyKernel()->db->escape($item['hint']);
        $item['keywords'] = Eresus_CMS::getLegacyKernel()->db->escape($item['keywords']);
        $item['content'] = Eresus_CMS::getLegacyKernel()->db->escape($item['content']);
        $item['options'] = Eresus_CMS::getLegacyKernel()->db->escape($item['options']);
        $result = Eresus_CMS::getLegacyKernel()->db->updateItem($this->table, $item, "`id`={$item['id']}");
        return $result;
    }
73646
protected function updateItem(Model $item, $data)
    {
        $this->beforeAssignData($item, $data);
        $item->assign($data, null, $this->whitelistUpdate());
        $this->afterAssignData($item, $data);

        $this->beforeSave($item);
        $this->beforeUpdate($item);

        $success = $item->update();

        if ($success) {

            $this->afterUpdate($item);
            $this->afterSave($item);
        }

        return $success ? $item : null;
    }
1355322
protected function append(array $item)
    {
        if (!$this->isEnabled()) {
            $this->enable();
        }

        $this->getContainer()->append($item);
    }